/***************************************************************************************
		All the functions has been made for Aslog Technologies
***************************************************************************************/
function __doValidate(ParamArray) {
	var GlobalArray = new Array();
	if(isArray(ParamArray)==true) {
		for(var i=0;i<ParamArray.length;i++) {
			ArrayString = ParamArray[i];
			// Spit for Seperation
			var detail = ArrayString.split(",");
			switch(detail[1]) {
				case "isEmpty":
					if(isEmpty(detail[0])==false) {
						GlobalArray[i] = "error";
					}
					break;
				case "isEmail":
					if(isEmail(detail[0])==false) {
						GlobalArray[i] = "error";
					}
					break;
				case "setCombo":
					if(setCombo(detail[0])==false) {
						GlobalArray[i] = "error";
					}
					break;
			}			
		}
		if(GlobalArray.length > 0) {
			return false;
		} else {
			return true;
		}
	} else {
		alert("Something Wrong into the Array    ");
		return false;
	}
}

function isArray(obj) {
	if(obj.constructor.toString().indexOf("Array")==-1) {
		return false;
	} else {
		return true;
	}
}

function isEmpty(controlId) {
	var d = window.document;
	var str = d.getElementById(controlId).value;
	if(str=="") {
		d.getElementById(controlId).className = "textbox_error";
		return false;
	} else {
		d.getElementById(controlId).className = "textbox";
		return true;
	}
}

function isEmail(controlId) {
	var d = window.document;
	var str = d.getElementById(controlId).value;
	if(str=="") {
		d.getElementById(controlId).className = "textbox_error";
		return false;
	} else {
		var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
		if(re.test(str)==false) {
			d.getElementById(controlId).className = "textbox_error";
			d.getElementById(controlId).value = "Invalid Email Format";
			return false;
		} else {
			d.getElementById(controlId).className = "textbox";
			return true;
		}
	}
}

function _doSelectionOnClick(controlId) {
	if(document.getElementById(controlId).value!="") {
		document.getElementById(controlId).select();
	}
}

/*********************************************************
		Start Functions for Contact Us page
*********************************************************/
function _doPostContact() {
	var validation_array = new Array();
	validation_array[0] = "contact_name,isEmpty";
	validation_array[1] = "contact_email,isEmail";
	validation_array[2] = "contact_comments,isEmpty";
	
	if(__doValidate(validation_array)==false) {
		return false;
	} else {
		var parameters;
		parameters = "full_name=" + encodeURIComponent(document.getElementById("contact_name").value);
		parameters+= "&email=" + encodeURIComponent(document.getElementById("contact_email").value);
		parameters+= "&phone=" + encodeURIComponent(document.getElementById("contact_phone").value);
		parameters+= "&description=" + encodeURIComponent(document.getElementById("contact_comments").value);
		
		document.getElementById("DisplayContactButton").className = "loading";
		document.getElementById("DisplayContactButton").innerHTML = "Data Submitting... Please Wait...";
		
		ajaxRequest = GetXmlHttpObject(getReplyContact);
		ajaxRequest.open("POST", "http://www.aslogtech.com/AjaxPostContact.php" , true);
		ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxRequest.setRequestHeader("Content-length", parameters.length);
		ajaxRequest.setRequestHeader("Connection", "close");
		ajaxRequest.send(parameters);
	}
}

function getReplyContact() {
	if(ajaxRequest.readyState==4 || ajaxRequest.readyState==200) {
		$(document).ready(function() {
			tb_show("Contact","http://www.aslogtech.com/modal.php?height=120&width=300&message=" + encodeURIComponent("Your data has been successfully submitted. Our representative will contact you shortly"),false);
		});
		document.getElementById("DisplayContactButton").innerHTML = "<a href=\"javascript:void(0);\" onclick=\"_doPostContact();\"><img src=\"http://www.aslogtech.com/images/submit.png\" width=\"115\" height=\"35\" border=\"0\" alt=\"\" /></a>";
		document.getElementById("contact_name").value = "";
		document.getElementById("contact_email").value = "";
		document.getElementById("contact_phone").value = "";
		document.getElementById("contact_comments").value = "";
	}
}
/*********************************************************
		End Functions for Contact Us page
		
		Start Functions for Quote Section
*********************************************************/
function _doPostQuote() {
	var validation_array = new Array();
	validation_array[0] = "quote_name,isEmpty";
	validation_array[1] = "quote_email,isEmail";
	validation_array[2] = "quote_description,isEmpty";
	
	if(__doValidate(validation_array)==false) {
		return false;
	} else {
		var parameters;
		parameters = "full_name=" + encodeURIComponent(document.getElementById("quote_name").value);
		parameters+= "&email=" + encodeURIComponent(document.getElementById("quote_email").value);
		parameters+= "&phone=" + encodeURIComponent(document.getElementById("quote_phone").value);
		parameters+= "&description=" + encodeURIComponent(document.getElementById("quote_description").value);
		
		document.getElementById("DisplayButton").className = "loading";
		document.getElementById("DisplayButton").innerHTML = "Data Submitting... Please Wait...";
		
		ajaxRequest = GetXmlHttpObject(ReturnQuote);
		ajaxRequest.open("POST", "http://www.aslogtech.com/AjaxPostQuote.php" , true);
		ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxRequest.setRequestHeader("Content-length", parameters.length);
		ajaxRequest.setRequestHeader("Connection", "close");
		ajaxRequest.send(parameters);
	}
}

function ReturnQuote() {
	if(ajaxRequest.readyState==4 || ajaxRequest.readyState==200) {
		$(document).ready(function() {
			tb_show("Online Quotation","http://www.aslogtech.com/modal.php?height=120&width=300&message=" + encodeURIComponent("Your quotation has been successfully sent. Our representative will contact you shortly"),false);
		});
		document.getElementById("DisplayButton").innerHTML = "<a href=\"javascript:void(0);\" onclick=\"_doPostQuote();\"><img src=\"http://www.aslogtech.com/images/get_quote.png\" alt=\"\" width=\"175\" height=\"41\" border=\"0\" /></a>";
		document.getElementById("quote_name").value = "";
		document.getElementById("quote_email").value = "";
		document.getElementById("quote_phone").value = "";
		document.getElementById("quote_description").value = "";
	}
}
/*********************************************************
		End Functions for Quote Section
		
		Start Fundtion for Pagination
*********************************************************/
function _doPaging(param,pWebsite,pCategory,pPage,pRecord) {
	var d = window.document;
	if(param == "record") {
		var str = d.getElementById('cRecord')[d.getElementById('cRecord').selectedIndex].value;
		var goto = pWebsite + "/portfolio/" + pCategory + "/" + pPage + "/" + str + ".aslog";
	} else if(param == "category") {
		var str = d.getElementById('cCategory')[d.getElementById('cCategory').selectedIndex].value;
		var goto = pWebsite + "/portfolio/" + str + "/1/" + pRecord + ".aslog";
	} else {
		var str = d.getElementById('cPage')[d.getElementById('cPage').selectedIndex].value;
		var goto = pWebsite + "/portfolio/" + pCategory + "/" + str + "/" + pRecord + ".aslog";
	}
	window.location.href = goto;
}

function _doDesignPaging(param,pWebsite,pCategory,pPage,pRecord) {
	var d = window.document;
	if(param == "record") {
		var str = d.getElementById('cRecord')[d.getElementById('cRecord').selectedIndex].value;
		var goto = pWebsite + "/design/" + pCategory + "/" + pPage + "/" + str + ".aslog";
	} else if(param == "category") {
		var str = d.getElementById('cCategory')[d.getElementById('cCategory').selectedIndex].value;
		var goto = pWebsite + "/design/" + str + "/1/" + pRecord + ".aslog";
	} else {
		var str = d.getElementById('cPage')[d.getElementById('cPage').selectedIndex].value;
		var goto = pWebsite + "/design/" + pCategory + "/" + str + "/" + pRecord + ".aslog";
	}
	window.location.href = goto;
}
/*********************************************************
		End Functions for Pagination
		
		Start Photo Slider Function
*********************************************************/
$(document).ready(function() {
	$("ul#banner").jBanner({height:325,width:389,padding:10,caption:false,cheight:35,delay:7000,speed:20});
});
/*********************************************************
		End Photo Slider Function
*********************************************************/
