// Form Confirm -----------------------------------------
function confirmSubmit(frm, btnVal) {
	if (confirm('Are you sure you want to do this?')) {
		if (!btnVal) {
			btnVal='delete';
		}
		frm.button.value=btnVal;
		frm.submit();
	} else {
		return;
	}
}

// AJAX Call Support ------------------------------------
var req;

function asyncRequest(url) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		if (url.indexOf('?') == -1) {
			url = url + ';' + new Date().getTime();
		} else {
			urlArray = url.split('?');
			url = urlArray[0] + ';' + new Date().getTime() + '?' + urlArray[1];
		}
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send("");
	}

	function processReqChange() {
	    // only if req shows "loaded"
	    if (req.readyState == 4) {
	        // only if "OK"
	        if (req.status == 200) {
	            // ...processing statements go here...
	            processAjaxResponse(); //Implement this function in the page
	        } else {
	            alert("There was a problem retrieving the XML data:\n" + req.statusText);
	        }
	    }
	}
}

function asyncPOSTRequest(url, parameters) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		if (url.indexOf('?') == -1) {
			url = url + ';' + new Date().getTime();
		} else {
			urlArray = url.split('?');
			url = urlArray[0] + ';' + new Date().getTime() + '?' + urlArray[1];
		}
		req.onreadystatechange = processReqChange;
		req.open('POST', url, true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", parameters.length);
		req.setRequestHeader("Connection", "close");
		req.send(parameters);
	}

	function processReqChange() {
	    // only if req shows "loaded"
	    if (req.readyState == 4) {
	        // only if "OK"
	        if (req.status == 200) {
	            // ...processing statements go here...
	            processAjaxResponse(); //Implement this function in the page
	        } else {
	            alert("There was a problem retrieving the XML data:\n" + req.statusText);
	        }
	    }
	}
}
function callHasValue(call) {
	var callArray = call.split(':');
	if (callArray[1] == '') {
		return false;
	}
	return true;
}
function validateCurrencyField(fld) {
	var Chars = "0123456789.,$";
	for (var i = 0; i < fld.value.length; i++) {
		if (Chars.indexOf(fld.value.charAt(i)) == -1) {
			return false;
		}
	}
	return true; 			
}
function getOffset(topSpace) {
	return (document.documentElement.scrollTop + topSpace);
}
function working(flag) {
	if (flag) {
	document.getElementById('responseMessage').style.top = getOffset(250) + 'px';
	document.getElementById('pageFilter').style.top = getOffset(0) + 'px';
		document.getElementById('responseMessage').style.visibility='visible';
		document.getElementById('pageFilter').style.visibility='visible';
	} else {
		document.getElementById('responseMessage').style.visibility='hidden';
		document.getElementById('pageFilter').style.visibility='hidden';
	}
}	
function hideTable() {
	document.getElementById('tableDiv').style.visibility='hidden';
	document.getElementById('pageFilter').style.visibility='hidden';
}
function showTable() {
	document.getElementById('tableDiv').style.top = getOffset(120) + 'px';
	document.getElementById('pageFilter').style.top = getOffset(0) + 'px';
	document.getElementById('tableDiv').style.visibility='visible';
	document.getElementById('pageFilter').style.visibility='visible';
}
function copyToClipBoard(id) {
	var fld = document.getElementById(id);
	window.clipboardData.setData('Text',fld.value);
	//alert(fld.value + ' Copied to Clipboard');
}
function currentWidth() {
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}	
function currentHeight() {
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		 //Non-IE
		 myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}
function formatCurrency(num) {
	if(isNaN(num)) {
		num = '0';
	}
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10) {
		cents = "0" + cents;
	}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}
	
	//return (((sign)?'':'-') + '$' + num + '.' + cents);
	return (((sign)?'':'-') + num + '.' + cents);
}	
function displayVideoCustom(vid) {
	var URL = '/web/public/static/video.view?my_Video='+vid+'.flv&my_FeatureHold=default.jpg';
	var foo = window.open(URL, 'wplayer', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=342,height=295');
}
function displayVideo(productId) {
	var URL = '/web/public/static/flash.view?my_Video='+productId+'.flv&my_FeatureHold='+productId+'.jpg';
	var foo = window.open(URL, 'wplayer', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=342,height=295');
}
// Usage: onkeypress="capLock(event)"
function capLock(e){
	kc = e.keyCode?e.keyCode:e.which;
	sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
	if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk)) {
		alert ( 'WARNING:\n\nCaps Lock is enabled\n\nThis field is case sensitive' );
	} else {

	}
}
