
var hostName = 'http://www.eschoolfunds.com.au';

function onLoadCommonFunction() {
	//MM_preloadImages('http://www.eschoolfunds.com.au/admin_images/slide_right.jpg');
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popupWindow(path, where, hite, wide){
	if (window.event){ 
		window.event.returnValue = false;   
	}
	var width;
	var height;
	var imgWidth;
	var imgHeight;
	
	if (screen.width<wide){
		width=screen.width-20;
		imgWidth=width-10;
		var windowX = (screen.width-width)/2;
	}
	else{
		var windowX = (screen.width-wide)/2;
		width=wide;
	}

	if (screen.height<hite){
		height=screen.height-70;
		imgHeight=height-20;
		var windowY = (screen.height-height)/2-30;
	}
	else{
		var windowY = (screen.height-hite)/2-10;
		height=hite;
	}

	var rand_no = Math.random();
	var i = Math.round(100*Math.random());
	if(screen.height<hite || screen.width<wide){
		var props=window.open(path, i, 'scrollbars=1,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	else{
		var props=window.open(path, i, 'scrollbars=1,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	props.moveTo(windowX,windowY);
}


if(window.ActiveXObject) {
	try {
		var oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch(e) {
		var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	}
} 
else {
	var oHTTP = new XMLHttpRequest();
}

if(window.ActiveXObject) {
	try {
		var oHTTP2 = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch(e) {
		var oHTTP2 = new ActiveXObject("Microsoft.XMLHTTP");
	}
} 
else {
	var oHTTP2 = new XMLHttpRequest();
}


/*******************************************************
For Check User Details
*******************************************************/
function checkUserName(){
	if(document.forms['userRegistration'].elements['user_name'].value==""){
		document.getElementById('textContentHTML').innerHTML = 'Please enter user name.';
		document.getElementById('theLayer').style.visibility = 'visible';	
		return false;
	}
	var userLoginName = document.forms['userRegistration'].elements['user_name'].value;
	var firstName = document.forms['userRegistration'].elements['first_name'].value;
	var lastName = document.forms['userRegistration'].elements['last_name'].value;
	
	checkUser(hostName+'/ajax_call.php?mode=check_username&user_name='+userLoginName+'&first_name='+firstName+'&last_name='+lastName+'');
}

function checkUser(page) {
	oHTTP.open("POST", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			document.getElementById('textContentHTML').innerHTML = getValue;
			document.getElementById('theLayer').style.visibility = 'visible';
		}
	}
	oHTTP.send(null);
}


function changeUsernameValue(val){
	document.forms['userRegistration'].elements['user_name'].value = val;
	hideMe(); 
	return false;
}

function check(){

if(document.pdetails.currency.value == "")
	{
	alert("Please Select Currency");
	document.pdetails.currency.focus();
	return false;
	}
if(document.pdetails.product_type.value == "")
	{
	alert("Please Select Product Type");
	document.pdetails.product_type.focus();
	return false;
	}
	if(document.pdetails.quantity.value == "")
	{
	alert("Please Select Quantity");
	document.pdetails.quantity.focus();
	return false;
	}
	return true;

}

function check_assort(){

if(document.assort_details.currency.value == "")
	{
	alert("Please Select Currency");
	document.assort_details.currency.focus();
	return false;
	}
if(document.assort_details.product_type.value == "")
	{
	alert("Please Select Product Type");
	document.assort_details.product_type.focus();
	return false;
	}
	/*if(document.assort_details.quantity.value == "")
	{
	alert("Please Select Quantity");
	document.assort_details.quantity.focus();
	return false;
	}*/
	return true;

}

function fill_data(){
	if(document.forms['fill'].elements['same'].checked == true) {
		document.fill.s_fname.value = document.fill.b_fname.value;
		document.fill.s_lname.value = document.fill.b_lname.value;
		document.fill.s_address1.value = document.fill.b_address1.value;
		document.fill.s_address2.value = document.fill.b_address2.value;
		document.fill.s_city.value = document.fill.b_city.value;
		document.fill.s_state.value = document.fill.b_state.value;
		document.fill.s_postcode.value = document.fill.b_postcode.value;
		document.forms['fill'].elements['s_country'].value = document.fill.elements['b_country'].value;
		
	} else {
		document.fill.s_fname.value = "";
		document.fill.s_lname.value = "";
		document.fill.s_address1.value = "";
		document.fill.s_address2.value = "";
		document.fill.s_city.value = "";
		document.fill.s_state.value = "";
		document.fill.s_postcode.value = "";
		document.forms['fill'].elements['s_country'].value = "";
	
	}

}

function rearch_check(){
	if(document.search.search_txt.value == "")
	{
		alert("Enter Design ID");
		document.search.search_txt.focus();
		return false;
	}
	//return true;
}

function load(){
	document.search.search_txt.focus();
}
function set_value(){
	ID = document.getElementById("sub_cat").value;
	ID1 = document.getElementById("sub_sub_cat").value;
	
	if(ID1 != ""){
		document.getElementById("sub_cat_hidden").value = document.getElementById("sub_sub_cat").value;
	} else{
		if(ID != ""){
			document.getElementById("sub_cat_hidden").value = document.getElementById("sub_cat").value;
		} else {
			document.getElementById("sub_cat_hidden").value = document.getElementById("category").value;
		}
	}
}

function form_submit(){
	document.forms['search'].submit();
}

function card_descriptions(){
	var card = document.getElementById('product_type').value;
    if(card==1){
    	document.getElementById('card_descriptions').innerHTML = '<img src="'+hostName+'/images/Postcard4x6.jpg" align="absmiddle" alt="Post Card" border="0" title="Post Card" class="changeStatus" />';
    }
    if(card==2){
    	document.getElementById('card_descriptions').innerHTML = '<img src="'+hostName+'/images/4x6.jpg" align="absmiddle" alt="Greeting Card 4 x 6" border="0" title="Greeting Card 4 x 6" class="changeStatus" />';
    }
    if(card==3){
    	document.getElementById('card_descriptions').innerHTML = '<img src="'+hostName+'/images/6x8.jpg" align="absmiddle" alt="Greeting Card 6 x 8" border="0" title="Greeting Card 6 x 8" class="changeStatus" />';
    }
    if(card==4){
    	document.getElementById('card_descriptions').innerHTML = '<img src="'+hostName+'/images/Giftwrap.jpg" align="absmiddle" alt="Book Giftwrap (A3)" border="0" title="Book Giftwrap (A3)" class="changeStatus" />';
    }
    if(card==5){
    	document.getElementById('card_descriptions').innerHTML = '<img src="'+hostName+'/images/Labels.jpg" align="absmiddle" alt="Labels (99.1mm x 67.7mm)" border="0" title="Labels (99.1mm x 67.7mm)" class="changeStatus" />';
    }
}

function price_list(){
	var ID = document.getElementById('currency').value;
	var ID2 = document.getElementById('product_type').value;
	var school = document.forms[0].schoolname.value;
	
	if(ID!=""){
		document.getElementById('price_listing').innerHTML = '<img src="'+hostName+'/images/newsletter_loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';

		changeDropdownResponse1(hostName+'/ajax_call.php?mode=price_show&id='+ID+'&school='+school+'&id2='+ID2);
	}
}

function changeDropdownResponse1(page) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			document.getElementById('price_listing').innerHTML = getValue;
		}
	}
	oHTTP.send(null);
}
/*
function changeDropdown_quantity(){
	//alert("test");
	var ID = document.getElementById('product_type').value;
	if(ID!=""){
		document.getElementById('change_quantity').innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeDropdownResponseQuantity(hostName+'/ajax_call.php?mode=quantity&id='+ID);
	}
}

function changeDropdownResponseQuantity(page) {
	oHTTP2.open("GET", page, true);
	oHTTP2.onreadystatechange=function() {
		if (oHTTP2.readyState==4) {
			var getValue=oHTTP2.responseText;
			document.getElementById('change_quantity').innerHTML = getValue;
		}
	}
	oHTTP2.send(null);
} 
*/
function changeDropdown_quantity(){
	//alert("test");
	var ID = document.getElementById('product_type').value;
	if(ID!=""){
		document.getElementById('change_quantity').innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeDropdownResponseQuantity(hostName+'/ajax_call.php?mode=quantity&id='+ID);
	}
}

function changeDropdownResponseQuantity(page) {
	oHTTP2.open("GET", page, true);
	oHTTP2.onreadystatechange=function() {
		if (oHTTP2.readyState==4) {
			var getValue=oHTTP2.responseText;
			document.getElementById('change_quantity').innerHTML = getValue;
		}
	}
	oHTTP2.send(null);
}

function changeDropdown_quantity_assort(total){
	//alert("test");
	var ID = document.getElementById('product_type').value;
	//alert(ID);
	if(ID!=""){
	for(i=0;i<total;i++){
		document.getElementById('change_quantity_assort_'+i).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		}
		changeDropdownResponseQuantityAssort(hostName+'/ajax_call.php?mode=quantity_assort&id='+ID,total);
	}
}

function changeDropdownResponseQuantityAssort(page,total) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			for(i=0;i<total;i++){
				document.getElementById('change_quantity_assort_'+i).innerHTML = getValue;
			}
		}
	}
	oHTTP.send(null);
} 
 


function advert_join(){
	if(document.advert_join_page.business_name.value == ""){
		document.advert_join_page.business_name.focus();
		alert("Please enter the business name");
		return false;
	}
	if(document.advert_join_page.abn.value == ""){
		document.advert_join_page.abn.focus();
		alert("Please enter the ABN number");
		return false;
	}
	if(document.advert_join_page.contact_address.value == ""){
		document.advert_join_page.contact_address.focus();
		alert("Please enter the Business Address");
		return false;
	}
	if(document.advert_join_page.contact_name.value == ""){
		document.advert_join_page.contact_name.focus();
		alert("Please enter a contact name");
		return false;
	}
	if(document.advert_join_page.contact_email.value != ""){
		var str=document.advert_join_page.contact_email.value;
		var er=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if(!er.test(str)) {
		document.advert_join_page.contact_email.focus();
		alert("Please enter valid email address");
		return false;
		}
	}
	if(document.advert_join_page.contact_phone.value == ""){
		document.advert_join_page.contact_phone.focus();
		alert("Please enter a contact phone");
		return false;
	}
	if(document.advert_join_page.business_nature.value == ""){
		document.advert_join_page.business_nature.focus();
		alert("Please enter a contact phone");
		return false;
	}
	if(document.advert_join_page.test_code.value == ""){
		document.advert_join_page.test_code.focus();
		alert("Please enter code");
		return false;
	}
	
	return true;
}

function contact_mail(){
	if(document.contact_page.client_name.value == ""){
		document.contact_page.client_name.focus();
		alert("Please enter your name");
		return false;
	}
	if(document.contact_page.company_name.value == ""){
		document.contact_page.company_name.focus();
		alert("Please enter company name");
		return false;
	}
	if(document.contact_page.web_address.value == ""){
		document.contact_page.web_address.focus();
		alert("Please enter web address");
		return false;
	}
	if(document.contact_page.email.value == ""){
		document.contact_page.email.focus();
		alert("Please enter email");
		return false;
	}
	if(document.contact_page.email.value != ""){
		var str=document.contact_page.email.value;
		var er=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if(!er.test(str)) {
		document.contact_page.email.focus();
		alert("Please enter valid email");
		return false;
		}
	}
	if(document.contact_page.comments.value == ""){
		document.contact_page.comments.focus();
		alert("Please enter some comments");
		return false;
	}
	if(document.contact_page.test_code.value == ""){
		document.contact_page.test_code.focus();
		alert("Please enter code");
		return false;
	}
	
	return true;
}

function gotourl(catid, pid){
		location.href='../assortment_details.php?catid='+catid+'&pid='+pid;
}

function check_signeture(){
	/*if(document.additional_item_signeture.signeture_quentity.value == ""){
		document.additional_item_signeture.signeture_quentity.focus();
		alert("Please enter signeture quantity");
		return false;
	}
	if(isNaN(document.additional_item_signeture.signeture_quentity.value)){
		document.additional_item_signeture.signeture_quentity.focus();
		alert("Please enter numeric value");
		return false;
	}*/
	if(document.additional_item_signeture.scart_product.value == ""){
		document.additional_item_signeture.scart_product.focus();
		alert("Please select product");
		return false;
	}
	if(document.additional_item_signeture.Upload_signeture.value == ""){
		document.additional_item_signeture.Upload_signeture.focus();
		alert("Please Upload a signature");
		return false;
	}
	return true;
}

function check_envelope(){
	if(document.additional_item_envelope.envelope_quentity.value == ""){
		document.additional_item_envelope.envelope_quentity.focus();
		alert("Please enter envelope quantity");
		return false;
	} 
	if(isNaN(document.additional_item_envelope.envelope_quentity.value)){
		document.additional_item_envelope.envelope_quentity.focus();
		alert("Please enter numeric value");
		return false;
	}
	if(document.additional_item_envelope.env_colour.value == ""){
		document.additional_item_envelope.env_colour.focus();
		alert("Please select envelope colour");
		return false;
	}
	
	if(document.additional_item_envelope.env_type.value == ""){
		document.additional_item_envelope.env_type.focus();
		alert("Please select type");
		return false;
	}
	if(document.additional_item_envelope.env_layout.value == ""){
		document.additional_item_envelope.env_layout.focus();
		alert("Please select layout");
		return false;
	}
	return true;
}

function changeDropdown_popup(){
	var ID = document.getElementById('category').value;
	if(ID!=""){
		document.getElementById('sub_category').innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeDropdownResponse_popup(hostName+'/ajax_call.php?mode=cat&id='+ID);
	}
}

function changeDropdownResponse_popup(page) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if(getValue == 0){
				document.forms['imageselect'].submit(); 
			} else {
				document.getElementById('sub_category').innerHTML = getValue;
			}
		}
	}
	oHTTP.send(null);
} 


function changeDropdown2_popup(){
	var ID = document.getElementById('sub_cat').value;
	if(ID!=""){
		document.getElementById('sub_sub_category').innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeDropdownResponse2_popup(hostName+'/ajax_call.php?mode=sub_cat&id='+ID);
	}
}

function changeDropdownResponse2_popup(page) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			//document.getElementById('sub_sub_category').innerHTML = page;
			if(getValue == 0){
				document.getElementById("sub_cat_hidden").value = document.getElementById("sub_cat").value;
				document.forms['imageselect'].submit();
			} else{
				document.getElementById('sub_sub_category').innerHTML = getValue;
			}
		}
	}
	oHTTP.send(null);
} 

function form_submit_popup(){
	document.forms['imageselect'].submit();
}

function radio_button_checker1()
{
var radio_choice = false;
//alert(document.checking.usp_cost.value);

for (counter = 0; counter < document.checking.usp_cost.length; counter++)
{
if (document.checking.usp_cost[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
	alert("Please select a method.")
	return (false);
}
	return (true);
}

function radio_button_checker()
{
var radio_choice = false;

for (counter = 0; counter < document.ups_other.usp_cost.length; counter++)
{
if (document.ups_other.usp_cost[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
	alert("Please select a method.")
	return (false);
}
	return (true);
}

function radio_button_checker_aus()
{
var radio_choice = false;

for (counter = 0; counter < document.ups_aus.usp_cost.length; counter++)
{
if (document.ups_aus.usp_cost[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
	alert("Please select a method.")
	return (false);
}
	return (true);
}




function changeCatDropdown(){
	var ID = document.getElementById('category_name').value;
	
	if(ID!=""){
		document.getElementById('sub_cat_name').innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeCatDropdownResponse(hostName+'/submitartwork.php?mode=root_cat&id='+ID);
	}
}

function changeCatDropdownResponse(page) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			document.getElementById('sub_cat_name').innerHTML = getValue;
		}
	}
	oHTTP.send(null);
} 

function openNewWindow(URLtoOpen,windowName,height,width)
{
	windowFeatures ="menubar=no,scrollbars=yes,location=no,favorites=no,resizable=no,status=no,toolbar=no,directories=no";
	var test = "'";
	winLeft = (screen.width-width)/2;
	winTop = (screen.height-(height+110))/2;
	windowName = windowName.replace(/ /g,"_");//Hai fixed to IE
	myWin= open(URLtoOpen,windowName,"width=" + width +",height=" + height + ",left=" + winLeft + ",top=" + winTop + test + windowFeatures + test);		
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
