function mywin(name){
	windowHandle = window.open('pic.php?n='+name,'UserPicture','height=130,width=250,screenX=10,screenY=10,top=10,left=150');
	windowHandle.focus();
}
function MM_openBrWindow(theURL,winName,type_features) {
	window.open(theURL,winName,type_features);
}
function printnow(str){
	windowHandle = window.open('printapplicationform.php?candidate_id='+str,'',',screenX=10,screenY=10,top=10,left=150,scrollbars=yes');
	windowHandle.focus();
}

function printspOrdernow(str){
	windowHandle = window.open('printsporderform.php?order_id='+str,'',',screenX=10,screenY=10,top=10,left=150,scrollbars=yes');
	windowHandle.focus();
}

function VersionDetails(cat_id,prod_id,ver_id,length_value,weight_value){
	var version_id=ver_id.split(',');
	location.replace("productdetail.php?cat_id="+cat_id+"&prod_id="+prod_id+"&ver_id="+version_id[0]+"&length_value="+length_value+"&weight_value="+weight_value)
}
function LengthDetails(cat_id,prod_id,ver_id,length_value,weight_value){
	var version_id=ver_id.split(',');
	location.replace("productdetail.php?cat_id="+cat_id+"&prod_id="+prod_id+"&ver_id="+version_id[0]+"&length_value="+length_value+"&weight_value="+weight_value)
}
function WeightDetails(cat_id,prod_id,ver_id,length_value,weight_value){
	var version_id=ver_id.split(',');
	location.replace("productdetail.php?cat_id="+cat_id+"&prod_id="+prod_id+"&ver_id="+version_id[0]+"&length_value="+length_value+"&weight_value="+weight_value)
}
//----------------------------------------------------------------- Candidate Page
function checkCandidateForm(){
	if(window.document.candidate.name.value == ""){
		alert('Name not given');
		window.document.candidate.name.focus();
		return;
	}
	if(window.document.candidate.email.value == ""){
		alert('Email not given');
		window.document.candidate.email.focus();
		return;
	}
	 if(window.document.candidate.age.value == ""){
		alert('Age not given');
		window.document.candidate.age.focus();
		return;
	}
	if(window.document.candidate.occupation.value == ""){
		alert('Occupation not given');
		window.document.candidate.occupation.focus();
		return;
	}
	if(window.document.candidate.mailingaddress.value == ""){
		alert('Mailing Address not given');
		window.document.candidate.mailingaddress.focus();
		return;
	}
	if(window.document.candidate.city.value == ""){
		alert('City not given');
		window.document.candidate.city.focus();
		return;
	}
	if(window.document.candidate.state.value == ""){
		alert('State not given');
		window.document.candidate.state.focus();
		return;
	}
	if(window.document.candidate.pcode.value == ""){
		alert('Postal Code not given');
		window.document.candidate.pcode.focus();
		return;
	}
	if(window.document.candidate.phone.value == ""){
		alert('Phone not given');
		window.document.candidate.phone.focus();
		return;
	}
	if(window.document.candidate.Yesorno[0].checked == false){
		if(window.document.candidate.Yesorno[1].checked == false){
			alert('Have you ever been Sponsored by any other brand! Option Not Checked');
			window.document.candidate.Yesorno.focus();
			return false;
		}
	}
	if(window.document.candidate.picture.value == ""){
		alert('Picture must be selected');
		window.document.candidate.picture.focus();
		return;
	}
	if(window.document.candidate.email.value != ""){
		var returnvalue = checkmail(window.document.candidate.email);
		if (returnvalue==true){
			document.candidate.submit();
		}
	}
}
//----------------------------------------------------------------- Edit Application Page
function checkEditForm(){
	if(window.document.count.name.value == ""){
		alert('Name not given');
		window.document.count.name.focus();
		return;
	}
	if(window.document.count.email.value == ""){
		alert('Email not given');
		window.document.count.email.focus();
		return;
	}
	if(window.document.count.age.value == ""){
		alert('Age not given');
		window.document.count.age.focus();
		return;
	}
	if(window.document.count.occupation.value == ""){
		alert('Occupation not given');
		window.document.count.occupation.focus();
		return;
	}
	if(window.document.count.mailingaddress.value == ""){
		alert('Mailing Address not given');
		window.document.count.mailingaddress.focus();
		return;
	}
	if(window.document.count.city.value == ""){
		alert('City not given');
		window.document.count.city.focus();
		return;
	}
	if(window.document.count.state.value == ""){
		alert('State not given');
		window.document.count.state.focus();
		return;
	}
	if(window.document.count.pcode.value == ""){
		alert('Postal Code not given');
		window.document.count.pcode.focus();
		return;
	}
	if(window.document.count.phone.value == ""){
		alert('Phone not given');
		window.document.count.phone.focus();
		return;
	}
	if(window.document.count.playedplaying.value == ""){
		alert('Played / Playing for ');
		window.document.count.playedplaying.focus();
		return;
	}
	if(window.document.count.experience.value == ""){
		alert('Experience in Field Hockey\n(Number of Years) not given');
		window.document.count.experience.focus();
		return;
	}
	if(window.document.count.positionofplay.value == ""){
		alert('Preferred Position of Play not given');
		window.document.count.positionofplay.focus();
		return;
	}
	if(window.document.count.email.value != ""){
		var returnvalue = checkmail(window.document.count.email);
		if (returnvalue==true){
			document.count.submit();
		}
	}
}
function Caution(application_id,candidate_product_id,candidate_id){
	answer = window.confirm("Are you sure you want to delete?");
	if(answer == true){
		location.replace("editapplication.php?action=del&cpid="+candidate_product_id+"&application_id="+application_id+"&candidate_id="+candidate_id);
	}
}
function CautionSP(order_id,sp_product_id,userId){
	answer = window.confirm("Are you sure you want to delete?");
	if(answer == true){
		location.replace("orderlist.php?action=del&sp_product_id="+sp_product_id+"&order_id="+order_id+"&userId="+userId);
	}
}

//----------------------------------------------------------------- Requirement Page
function checkRequirementForm(){
	var flag=1;
	var pid = window.document.getElementsByName("product_id[]");
	var i=0;
	while(i< pid.length){
		if(pid[i].value==0 || pid[i].value=="cat"){
			var count = i+1;
			falg=0;
			alert("Please select any product in row " + count);
			break;
		}
		else
			i++	;
	}
	if(i==pid.length){
		if(window.document.count.list[0].checked == false && window.document.count.list[1].checked == false){
			alert('Please select sponsorship package');
			return;
		}
		if(window.document.count.agreed.checked == false){
			alert('Check agreement box');
			return;
		}
		if(window.document.count.playedplaying.value == ""){
			alert('Played / Playing for ');
			window.document.count.playedplaying.focus();
			return;
		}
		if(window.document.count.experience.value == ""){
			alert('Experience in Field Hockey\n(Number of Years)');
			window.document.count.experience.focus();
			return;
		}
		if(window.document.count.positionofplay.value == ""){
			alert('Preferred Position of Play\n(Number of Years)');
			window.document.count.positionofplay.focus();
			return;
		}
		document.count.submit();
	}
}
// ---------------------------------------------------------------- Product Page --> Submit Email
var xmlHttpSEmail;
function SubmitEmail(email,prod_name,length_value,weight_value,versionname){
	if(email=="" || email==" Enter Your Email Here"){
		alert("Please check - Email Field is Empty or not given!");
		document.cartform.email_cust.focus();
		return;
	}
	if(email!="" || email!=" Enter Your Email Here"){
		var returnvalue=checkmail(window.document.cartform.email_cust);
		if (returnvalue==true){
			xmlHttpSEmail=GetXmlHttpObject();
			if (xmlHttpSEmail==null){
				alert ("Browser does not support HTTP Request");
				return;
			}
			var url="submitemail.php?email="+email+"&sid="+Math.random()+"&prod_name="+prod_name+"&prod_length="+length_value+"&prod_weight="+weight_value+"&prod_version="+versionname;
			xmlHttpSEmail.onreadystatechange=SubmitEmailDone;
			xmlHttpSEmail.open("GET",url,true);
			xmlHttpSEmail.send(null);
		}
	}
}
function SubmitEmailDone(){ 
	if (xmlHttpSEmail.readyState==4 || xmlHttpSEmail.readyState=="complete"){
		document.getElementById("submit_successfully").innerHTML=xmlHttpSEmail.responseText;
	} 
}
// ---------------------------------------------------------------- Send Email
var xmlHttpEmail
function sendEmail(yn,ym,e1,e2,e3,e4,e5){
	if(yn == ""){
		alert("Please check - Name Field is Empty!");
		document.taf.yn.focus();
		return;
	}
	if(ym == ""){
		alert("Please check - Your Email Field is Empty!");
		document.taf.ym.focus();
		return;
	}
	if(ym != ""){
		var returnvalue = checkmail(window.document.taf.ym);
		if (returnvalue==true){
			if(e1 == ""){
				alert("Please check - Atleast provide one email!");
				document.taf.m1.focus();
				return;
			}
			if(e1 != ""){
				var returnvalue = checkmail(window.document.taf.m1);
				if (returnvalue==true){
					xmlHttpEmail=GetXmlHttpObject();
					if (xmlHttpEmail==null){
						alert ("Browser does not support HTTP Request");
						return;
					}
					var url="sendemail.php?yn="+yn+"&sid="+Math.random()+"&ym="+ym+"&m1="+e1+"&m2="+e2+"&m3="+e3+"&m4="+e4+"&m5="+e5;
					xmlHttpEmail.onreadystatechange=stateChangedEmail;
					xmlHttpEmail.open("GET",url,true);
					xmlHttpEmail.send(null);
				}
			}
		}
	}
}
function stateChangedEmail(){ 
	if (xmlHttpEmail.readyState==4 || xmlHttpEmail.readyState=="complete"){	
		document.getElementById("EmailStatus").innerHTML=xmlHttpEmail.responseText
	} 
}
// --------------------------------------- Show Properties
var xmlHttpShowProperties
function showProperties(prod_id,str1){	

	xmlHttpShowProperties=GetXmlHttpObject();
	if (xmlHttpShowProperties==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	document.count.spannumber.value = "txtProp"+str1;
	document.getElementById(document.count.spannumber.value).innerHTML= ' &nbsp;<img src="images/loading_fb.gif">';
	if(prod_id=='' || prod_id==0){
		document.getElementById(document.count.spannumber.value).innerHTML= '';
		return;
	}
	var url="addproperty.php?prod_id="+prod_id+"&sid="+Math.random()+"&spno="+str1;
	xmlHttpShowProperties.onreadystatechange=stateChangedShowProperty
	xmlHttpShowProperties.open("GET",url,true)
	xmlHttpShowProperties.send(null)
}
function stateChangedShowProperty(){ 
	if (xmlHttpShowProperties.readyState==4 || xmlHttpShowProperties.readyState=="complete"){	
		var div_id = document.count.spannumber.value;
		setTimeout(document.getElementById(div_id).innerHTML=xmlHttpShowProperties.responseText,200);
	} 
}



function showPropertiesEdit(prodCat,str1){
	
	prodCt = prodCat.split(",");
	cat = prodCt[0];

	mod = prodCt[3];
	mod = prodCt[3];
	if(mod=='' || mod==null){	
	mod='s';
	prod_id = prodCt[1];
	}
	else{
		prod_id = prodCt[2];
	}

	xmlHttpShowProperties=GetXmlHttpObject();
	if (xmlHttpShowProperties==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	document.count.spannumber.value = "txtProp"+str1;
	document.getElementById(document.count.spannumber.value).innerHTML= ' &nbsp;<img src="images/loading_fb.gif">';
	if(prod_id=='' || prod_id==0){
		document.getElementById(document.count.spannumber.value).innerHTML= '';
		return;
	}
	if(mod=='s')
	var url="addproperty_edit.php?act=edit&prod_id="+prod_id+"&sid="+Math.random()+"&spno="+str1;
	else
	var url="addproperty_other.php?act=edit&mod="+ mod +"&prod_id="+prod_id+"&sid="+Math.random()+"&spno="+str1;

	xmlHttpShowProperties.onreadystatechange=stateChangedShowProperty
	xmlHttpShowProperties.open("GET",url,true)
	xmlHttpShowProperties.send(null)
}
function stateChangedShowProperty(){ 
	if (xmlHttpShowProperties.readyState==4 || xmlHttpShowProperties.readyState=="complete"){	
		var div_id = document.count.spannumber.value;
		setTimeout(document.getElementById(div_id).innerHTML=xmlHttpShowProperties.responseText,200);
	} 
}

var xmlHttpShowProperties
function showPropertiesOther(prod_id,str1,mod){	
	xmlHttpShowProperties=GetXmlHttpObject();
	if (xmlHttpShowProperties==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	if(mod=='b')
	DVID = document.count.spannumberbag.value = "txtPropBag"+str1;
	if(mod=='bl')
	DVID = document.count.spannumberball.value = "txtPropBall"+str1;
	if(mod=='p')
	DVID = document.count.spannumberprotection.value = "txtPropProtection"+str1;
	if(mod=='a')
	DVID = document.count.spannumberaccessories.value = "txtPropAccessories"+str1;
	if(mod=='sw')
	DVID = document.count.spannumberaccessories.value = "txtPropSportswear"+str1;
	if(prod_id=='' || prod_id==0){
		document.getElementById(DVID).innerHTML= '';
		return;
	}
	document.getElementById(DVID).innerHTML= ' &nbsp;<img src="images/loading_fb.gif">';
	var url="addproperty_other.php?mod="+ mod +"&prod_id="+prod_id+"&sid="+Math.random()+"&spno="+str1;
	xmlHttpShowProperties.onreadystatechange=stateChangedShowPropertyOther
	xmlHttpShowProperties.open("GET",url,true)
	xmlHttpShowProperties.send(null)
}
function stateChangedShowPropertyOther(){ 
	if (xmlHttpShowProperties.readyState==4 || xmlHttpShowProperties.readyState=="complete"){	
		var div_id = DVID ;
		setTimeout(document.getElementById(div_id).innerHTML=xmlHttpShowProperties.responseText ,200);
		setTimeout(tb_init('a.thickbox, area.thickbox, input.thickbox') ,200);
		
		
		
	} 
}


// --------------------------------------- Add Row
var xmlHttpAddRow
function AddRow(){	
	xmlHttpAddRow=GetXmlHttpObject();
	if (xmlHttpAddRow==null){
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var inc = parseInt(document.count.count.value) + 1;
	var url="addrow.php?q="+inc+"&sid="+Math.random();
	var div_id = "txtHint" + document.count.count.value;
	document.getElementById(div_id).innerHTML= ' &nbsp;<img src="images/loading_fb.gif">';
	xmlHttpAddRow.onreadystatechange=stateChangedAddRow
	xmlHttpAddRow.open("GET",url,true)
	xmlHttpAddRow.send(null)
}
function stateChangedAddRow(){ 
	if (xmlHttpAddRow.readyState==4 || xmlHttpAddRow.readyState=="complete"){	
		var div_id = "txtHint" + document.count.count.value;
		setTimeout(document.getElementById(div_id).innerHTML=xmlHttpAddRow.responseText,200);
		var inc = parseInt(document.count.count.value) + 1;
		document.count.count.value = inc;
	} 
}





var xmlHttpAddRow
function AddRowOther(mod){	
	MOD = mod;
	xmlHttpAddRow=GetXmlHttpObject();
	if (xmlHttpAddRow==null){
		alert ("Browser does not support HTTP Request");
		return;
	} 

	if(mod=='b'){
	INCELM = document.count.countbag;	
	var incBag = INCVAL = parseInt(INCELM.value) + 1;
	var url="addrowOther.php?q="+incBag+"&sid="+Math.random();
	SPNTYP='txtbag';
	}
	if(mod=='bl'){
	INCELM = document.count.countball;	
	var incBall = INCVAL = parseInt(INCELM.value) + 1;
	var url="addrowOther.php?q="+incBall+"&sid="+Math.random();
	SPNTYP='txtball';
	}
	if(mod=='a'){
		INCELM = document.count.countaccessories;	
		var incAccessories = INCVAL = parseInt(INCELM.value) + 1;
		var url="addrowOther.php?q="+incAccessories+"&sid="+Math.random();
		SPNTYP='txtaccessories';
	}
	if(mod=='p'){
		INCELM = document.count.countprotection;	
		var incProtection = INCVAL = parseInt(INCELM.value) + 1;
		var url="addrowOther.php?q="+incProtection+"&sid="+Math.random();
		SPNTYP='txtprotection';
	}
	if(mod=='sw'){
		INCELM = document.count.countprotection;	
		var incSportsWear = INCVAL = parseInt(INCELM.value) + 1;
		var url="addrowOther.php?q="+incSportsWear+"&sid="+Math.random();
		SPNTYP='txtsportswear';
	}
	var div_id = SPNTYP + parseInt(INCVAL-1);
	document.getElementById(div_id).innerHTML= ' &nbsp;<img src="images/loading_fb.gif">';
	url = url+"&mod="+mod;
	xmlHttpAddRow.onreadystatechange=stateChangedAddRowOther
	xmlHttpAddRow.open("GET",url,true)
	xmlHttpAddRow.send(null)
}
function stateChangedAddRowOther(){ 
	if (xmlHttpAddRow.readyState==4 || xmlHttpAddRow.readyState=="complete"){
		
		var div_id = SPNTYP + parseInt(INCVAL-1);
		setTimeout(document.getElementById(div_id).innerHTML=xmlHttpAddRow.responseText,200)
		var incV = parseInt(INCVAL);
		INCELM.value = incV;
	} 
}

//function checkAll(theForm, cName) {
//	for (i=0,n=theForm.elements.length;i<n;i++)
//		if (theForm.elements[i].className.indexOf(cName) !=-1)
//		if (theForm.elements[i].checked == true) {
//		theForm.elements[i].checked = false;
//	} else {
//		theForm.elements[i].checked = true;
//	}
//}

function checkAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
}
//----------------------------------------------- Getting XmlHttp Object
function GetXmlHttpObject(){
	var objXMLHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		objXMLHttp=new XMLHttpRequest();
	}
	catch (e){
		// Internet Explorer
		try{
			objXMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return objXMLHttp;
}
//------------------------------------------ Email Verifier
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
function checkmail(e){
	var returnval=emailfilter.test(e.value)
	if (returnval==false){
		alert("Please enter a valid email address.")
		e.select()
	}
	return returnval;
}

function changeOrderStatusForm(frm,order_id){
$.ajax({
   type: "POST",
   url: "ajax.php",
   data: "order_id="+order_id,
   success: function(msg){
	 frm.submit();
   }
 });
	
}
