// ==|Sirius - AJAX |=================================================== //
// ==|Author : Tom Wilson -SB |========================================= //
// ~~|Inital Function|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// ~~|Params:Form = The Form thats Ajax is Sending|~~~~~~~~~~~~~~~~~~~~~ //
// ~~|Params:URL = Where the Form is Being Submited|~~~~~~~~~~~~~~~~~~~~ //
// ~~|Params:ID = ID of HTML Element to send returned Value|~~~~~~~~~~~~ //
function ajax(params,url,id) {
	//var formParams = buildFormVars(form)
	AjaxCall(params, url, id);
}
	
// ~~|Start Ajax Call|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //

function AjaxCallTabs(parameters, url, id) {
	var ajaxReq = false;
		// ~~|Create HTTP Request Object|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
		// ~~|Try For Moz,Op,Saf,Kon,Epif,ect...|~~~~~~~~~~~~~~~~~~~~~ //
		 if (window.XMLHttpRequest) {
		    ajaxReq = new XMLHttpRequest();
		    if (ajaxReq.overrideMimeType) {
			  ajaxReq.overrideMimeType('text/html');
		    }
		// ~~|Try For IE, And Then Again depending on the Version of MSXML| //
		 } else if (window.ActiveXObject) { // IE
		    try {
			  ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch (e) {
			  try {
				ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (e) {}
		    }
		 }
		 
		// ~~|If All Calls Fail, Appologize...|~~~~~~~~~~~~~~~~~~~~~~~~ //
		 if (!ajaxReq) {
		    alert('Cannot create XMLHTTP instance, Sorry.');
		    return false;
		 }
		 
	// ~~|Start Setting up XMLHTTP Object Instance|~~~~~~~~~~~~~~~~~~~~~ //
	 
	//Loading Message 	

	 
	// ~~|Using Post?|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
	// ajaxReq.open('post', url, true);
	 //ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	 //ajaxReq.setRequestHeader("Content-length", parameters.length);
	// ajaxReq.setRequestHeader("Connection", "close");
	// ~~|Using Get?|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /

	 ajaxReq.open('get', url + '?' + parameters + "&iecachefix=" + new Date().getTime(), true);
	 ajaxReq.send(null);
	 
	 ajaxReq.onreadystatechange = function(){
	// ~~|Stick Returned String in Specificed Tag|~~~~~~~~~~~~~~~~~~~~~~~ //
		 if (ajaxReq.readyState == 4 || ajaxReq.readyState == "complete") {
		    if (ajaxReq.status == 200) {
			  $('#' + id).html(ajaxReq.responseText);
			  //document.getElementById(id).innerHTML = ajaxReq.responseText;   
			  executeScriptsOnResponse( id, ajaxReq.responseText );
	// ~~|Error, Let the People Know|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
		    } else {
			  //document.getElementById(id).innerHTML = 'There was a problem with the request.';
		    }
		 }	 
	 }
}

function AjaxCall(parameters, url, id) {

	var ajaxReq = false;
	// ~~|Create HTTP Request Object|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
	// ~~|Try For Moz,Op,Saf,Kon,Epif,ect...|~~~~~~~~~~~~~~~~~~~~~ //
	if (window.XMLHttpRequest) {
		ajaxReq = new XMLHttpRequest();
		if (ajaxReq.overrideMimeType) {
			ajaxReq.overrideMimeType('text/html');
		}
	// ~~|Try For IE, And Then Again depending on the Version of MSXML| //
	} else if (window.ActiveXObject) { // IE
		try {
			ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	}
	 
	// ~~|If All Calls Fail, Appologize...|~~~~~~~~~~~~~~~~~~~~~~~~ //
	if (!ajaxReq) {
		alert('Cannot create XMLHTTP instance, Sorry.');
		return false;
	}
		 
	// ~~|Start Setting up XMLHTTP Object Instance|~~~~~~~~~~~~~~~~~~~~~ //
	if (document.getElementById("divStaIdBox") != null){
		document.getElementById('divStaIdBox').style.display = 'none';
	}
	
	//if( document.getElementById('tdOne') != null ) {
		document.getElementById('divCntntWrap').style.opacity = '.15';
		document.getElementById('divCntntWrap').style.filter = 'alpha(opacity=15)';
		document.getElementById('LoadingDog').style.visibility = 'visible';
	//}
	ajaxReq.open('get', url + '?' + parameters.replace("&","%26") + "&iecachefix=" + new Date().getTime(), true);
	ajaxReq.send(null);
 
	ajaxReq.onreadystatechange = function() {
		if (ajaxReq.readyState == 4 || ajaxReq.readyState == "complete") {
			if (ajaxReq.status == 200) {
				$('#' + id).html(ajaxReq.responseText);
				document.getElementById('divCntntWrap').style.opacity = '1';
				document.getElementById('divCntntWrap').style.filter = 'none';
				document.getElementById('LoadingDog').style.visibility = 'hidden';
				executeScriptsOnResponse( id, ajaxReq.responseText );
			} else {
				document.getElementById(id).innerHTML = 'There was a problem with the request1.';
			}
		}	 
	}
	//document.getElementById('tblCntnr').style.height = "100%";
}

function executeScriptsOnResponse(divId,html){

	//document.getElementById( divId ).innerHTML = html;
	
	var block = /\<script.*?\>[\s\S]*?\<\/.*?script\>/igm;
	var scripts = html.match(block), errorStr = "";
	
//	for( var i = 0; i< scripts.length; i++ ) {
//		var js = scripts[i].replace(/\<script[\w\W]+?\>/i,"").replace(/\<\/script\s*\>/i,"");
//		try {
//			eval( js );
//		} catch( err ) {
//			errorStr += "\n" + String(err);
//		}
//	}
//	if( errorStr.length > 0 )
//		document.getElementById( divId ).innerHTML = errorStr;
}


function AjaxCallSel(parameters, url, id) {
	var ajaxReq = false;
		// ~~|Create HTTP Request Object|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
		// ~~|Try For Moz,Op,Saf,Kon,Epif,ect...|~~~~~~~~~~~~~~~~~~~~~ //
		 if (window.XMLHttpRequest) {
		    ajaxReq = new XMLHttpRequest();
		    if (ajaxReq.overrideMimeType) {
			  ajaxReq.overrideMimeType('text/html');
		    }
		// ~~|Try For IE, And Then Again depending on the Version of MSXML| //
		 } else if (window.ActiveXObject) { // IE
		    try {
			  ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch (e) {
			  try {
				ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (e) {}
		    }
		 }
		 
		// ~~|If All Calls Fail, Appologize...|~~~~~~~~~~~~~~~~~~~~~~~~ //
		 if (!ajaxReq) {
		    alert('Cannot create XMLHTTP instance, Sorry.');
		    return false;
		 }
		 
	// ~~|Start Setting up XMLHTTP Object Instance|~~~~~~~~~~~~~~~~~~~~~ //
	if (document.getElementById("divStaIdBox") != null){
		document.getElementById('divStaIdBox').style.display = 'none';
		}
	document.getElementById('mainColumn').style.opacity = '.15';
	document.getElementById('mainColumn').style.filter = 'alpha(opacity=15)';
	document.getElementById('LoadingDog').style.visibility = 'visible';
	// ~~|Using Post?|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
	// ajaxReq.open('post', url, true);
	 //ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	 //ajaxReq.setRequestHeader("Content-length", parameters.length);
	// ajaxReq.setRequestHeader("Connection", "close");
	// ~~|Using Get?|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
	//alert(url + '?' + parameters.replace("&","%26") + "&iecachefix=" + new Date().getTime());
	 //ajaxReq.open('get', url + '?' + parameters.replace("&","%26") + "&iecachefix=" + new Date().getTime(), true);
	 ajaxReq.open('get', url + '?' + parameters + "&iecachefix=" + new Date().getTime(), true);
	 ajaxReq.send(null);
	 
	 ajaxReq.onreadystatechange = function(){
	// ~~|Stick Returned String in Specificed Tag|~~~~~~~~~~~~~~~~~~~~~~~ //
		 if (ajaxReq.readyState == 4 || ajaxReq.readyState == "complete") {
		    if (ajaxReq.status == 200) {
			  $('#' + id).html(ajaxReq.responseText);
			  //document.getElementById(id).innerHTML = ajaxReq.responseText;
			  document.getElementById('mainColumn').style.opacity = '1';
			  document.getElementById('mainColumn').style.filter = 'none';
			  document.getElementById('LoadingDog').style.visibility = 'hidden';
			 // executeScriptsOnResponse( id, ajaxReq.responseText );
	// ~~|Error, Let the People Know|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
		    } else {
			  document.getElementById(id).innerHTML = 'There was a problem with the request1.';
		    }
		 }	 
	 }
document.getElementById('tblCntnr').style.height = "100%";

}
	
	
// ~~|This Builds the String to be sent via Ajax From the Form|~~~~~~~~~~ //
function buildFormVars(form){
	var ajaxForm = document.forms[0]
	var rtrnParam = ""
	for(i=0; i<ajaxForm.elements.length; i++){
		// Text Varibles
		if(ajaxForm.elements[i].type == "text" || ajaxForm.elements[i].type == "textarea" || ajaxForm.elements[i].type == "button"){
			rtrnParam += ajaxForm.elements[i].name + "=" + encodeURI(ajaxForm.elements[i].value) + "&"
		}
		// Checkboxs Varibles
		else if(ajaxForm.elements[i].type == "checkbox"){
			rtrnParam += ajaxForm.elements[i].name + "=" + encodeURI(ajaxForm.elements[i].checked) + "&"
		}
		// Select Varibles
		else if(ajaxForm.elements[i].type == "select-one"){
			rtrnParam += ajaxForm.elements[i].name + "=" + encodeURI(ajaxForm.elements[i].options[ajaxForm.elements[i].selectedIndex].text) + "&"
		}
	}
	return(rtrnParam);
	//alert(rtrnParam);
}

// ~~|Flash Functions|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
function ChnFlahHght(varHeight){
document.getElementById('channelsOverview').style.overflow = "hidden";
document.getElementById('channelsOverview').style.height = varHeight + "px";
}

function ProdListHght(varHeight){
	if (document.getElementById("divProductList") != null){
		document.getElementById('divProductList').style.height = varHeight + "px";
	}
}