var sInvalidChars
sInvalidChars="1234567890";
var iTotalChecked=0;
function checkNumericVals(objV,  msg)
{
	for(var i=0;i<sInvalidChars.length;i++)
	{
		if(objV.value.indexOf(sInvalidChars.charAt(i))!=-1)
		{
			alert(msg);
			objV.focus();
			return false;
		}
	}
	return true;
}
function objChecked(obj)
{
	if(obj.checked)
		iTotalChecked = iTotalChecked + 1
	else
		iTotalChecked = iTotalChecked - 1
 }
function fnSearch(iID)
{
	document.forms[0].HID_SearchID.value=iID;
	document.forms[0].action="../Users/Search.asp"
	document.forms[0].submit();
}
function fn_ValidateZipPhone(obj, iLen, sMsg)
{
	if(obj.value.length<iLen)
	{
		alert(sMsg);
		obj.select();
		obj.focus();
		return false;
	}
	return true;
}

function CheckConfirmPassword(fldPass,fldConPass,minChars)
{
	//created on: 30th Jan 2003
	//Programmer: Anita Mourya
	//Purpose	: This function is used to check that Password contains minimum characters and confirm Password matches the password. 
	//Arguments : password field name , confirm password field name, minimum characters to check.


		if(fldPass.value.length == 0)
		{
			alert("Please enter your password");
			fldPass.focus();
			fldPass.select();
			return false;
		}
		h = fldPass.value.length;
		x = fldPass.value.value;

			for( i=0;i<h;i++)
			{
			 
				if (  h < minChars )
				{
								alert(" Password can't be less than " + minChars + " characters");
								fldPass.focus();
								fldPass.select();
								return false;
				}


			}
		//=============================


		if(fldConPass.value.length == 0)
		{
			alert("Please re-enter your password");
			fldConPass.focus();
			fldConPass.select();
			return false;
		}
	
//	alert(fldPass.value);	
	//	alert(fldConPass.value);
		if(fldPass.value != fldConPass.value)
		{
			alert("Please ensure that you have entered the same password twice");
			fldConPass.focus();
			fldConPass.select();
			return false;
		}
	return true;

}


function CheckCharWithinField(fldName, fldAlias, chkChar)
{
	//created on: 30th Jan 2003
	//Programmer: Anita Mourya
	//Purpose	: This function is used to check that username does not contain any spaces. 
	//Arguments : field name object, field alias to be used, character to be checked

		b= fldName.value.length
		x= fldName.value
		
		if (x == "")
		{
			alert ("Please Enter Your " + fldAlias)
			fldName.focus();
			fldName.select();
			return false;
		}

		for( i=0;i<b;i++)
		{
			z = x.substring(i,i+1);
			if(z== chkChar)
			{
				alert("Please enter valid " + fldAlias + " without any '" + chkChar + "' in-between");
				fldName.focus();
				fldName.select();
				return false;
			}
		}
		//------------------------------

return true;
}
function SendtoPopup(obj,objaction,iwidth,iheight)
{
	if(ValidateForm(obj))
	{
		iLeft = parseInt(screen.width)/2-parseInt(iwidth)/2
		iTop = parseInt(screen.height)/2-parseInt(iheight)/2
		obj.target = "s"
		obj.method = "Post"
		obj.action = objaction
		win = 	window.open(objaction, "s", "toolbars=0, menubar=0, noresize, left=" + iLeft + ",top=" + iTop + ", width=" + iwidth + ", height=" + iheight)
		obj.submit(win)
	}
	else
	{
		return false;
	}
	return false;
}
function CheckAll(chk)
{
	
	//created on: 10th May 2002
	//Programmer: Prashant Sharma
	//Purpose	: This function is used to check all the checkboxes basedon state of chk checkbox. 
	//Arguments : checkbox object
	for (var i=0;i < document.forms[0].elements.length;i++)
	{
		var e = document.forms[0].elements[i];
		if (e.type == "checkbox")
		{
			e.checked = chk.checked;
		}
	}
}
function CheckAlls(){
	var frm=document.formn;
	var count = frm.elements.length;
	
			if(document.formn.chk.checked == 0){
				
				for (i=0; i < count; i++){
					if(frm.elements[i].type=="checkbox"){
						frm.elements[i].checked = 0;
						document.getElementById('noBlank').value='';
						document.formn.chk.checked=0;
						
					}
				}
			} 
			if(document.formn.chk.checked == 1 ){
				
				for (i=0; i < count; i++){
					
					if(frm.elements[i].type=="checkbox"){
						frm.elements[i].checked = 1;
						document.getElementById('noBlank').value='1';
						document.formn.chk.checked=1;
					}
				}
			} 
	
}

function checkBx(len){
	var flag=false;
	for(var x=1;x<len;x++){
				if(document.getElementById("ck_"+x).checked){
					flag=true;
					break;
				}
				
		}
		if(flag){
				document.getElementById('noBlank').value='1';
		}else
				document.getElementById('noBlank').value='';
	
		
}
function validateFrm(){
		if(document.getElementById('noBlank').value==''){
			alert("Please check at leat one product.");
			return false;
		}
		return confirm("Are you sure to delete selected product(s)?");
}
function checkQty(len){
		for(var x=1;x<len;x++){
				if(document.getElementById('qty_'+x).value==""){
					alert("Please enter product quantity");
					document.getElementById('qty_'+x).focus();
					return false;
					break;
				}
				else if(document.getElementById('qty_'+x).value<=0){
					alert("Please enter proper quantity");
					document.getElementById('qty_'+x).focus();
					return false;
					break;
				}else if(isNaN(document.getElementById('qty_'+x).value)){
					alert("Product quantity must be numeric only");
					document.getElementById('qty_'+x).focus();
					return false;
					break;
				}
		}
	
		
}
function fnRemoveSpaces(sFldval)
{
  var sTemp=sFldval;
  var sNewval=sTemp;
  //remove spaces from the front
  for(var i=0;i<sTemp.length;i++)
  {	
		if(sTemp.charAt(i)!=" ")
			break;
		else
			sNewval = sTemp.substring(i+1);
  }
	return sNewval;
}

function fnFixSpace(sFldval)
{
	//created on: 10th May 2002
	//Programmer: Prashant Sharma
	//Purpose	: This function is used to remove spaces. 
	//Arguments : text field object value
	var sTemp=sFldval;
  var sReversedString="";
  var sTemp1;
  
  //remove spaces from the front
  sNewval = fnRemoveSpaces(sTemp);
  
  // reverse n remove spaces from the front
  for(var i=sNewval.length-1;i>=0;i--)
		sReversedString = sReversedString + sNewval.charAt(i);
	sTemp1 = fnRemoveSpaces(sReversedString);
	//reverse again
	sReversedString="";
	for(var i=sTemp1.length-1;i>=0;i--)
		sReversedString = sReversedString + sTemp1.charAt(i);
	sNewval = sReversedString;
	return sNewval;
}

function ValidateEMail(objName)
{
	//created on: 12th May 2002
	//Programmer: Naveen Sharma
	//Purpose	: This function is used to validate email. 
	//Arguments : Email object
		
	var sobjValue;
	var iobjLength;
	
	sobjValue=objName;
	iobjLength=sobjValue.length;
	iFposition=sobjValue.indexOf("@");
	iSposition=sobjValue.indexOf(".");
	iTmp=sobjValue.lastIndexOf(".");	
	iPosition=sobjValue.indexOf(",");
	iPos=sobjValue.indexOf(";");
	
	if (iobjLength!=0)
	{
		if ((iFposition == -1)||(iSposition == -1))
		{
			return false;
		}
		else if(sobjValue.charAt(0) == "@" || sobjValue.charAt(0)==".")
		{
			return false;				
		}
		else if(sobjValue.charAt(iobjLength) == "@" ||
sobjValue.charAt(iobjLength)==".")
		{
			return false;				
		}	
		else if((sobjValue.indexOf("@",(iFposition+1)))!=-1)
		{	
			return false;
		}
		else if ((iobjLength-(iTmp+1)<2)||(iobjLength-(iTmp+1)>3))
		{
			return false;
		}
		else if ((iPosition!=-1) || (iPos!=-1))
		{
			return false;
		}
		else
		{
			return true;
		}		
	}		
}

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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  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];}
}

/*--------------------------------------------------------------------------------------
	this sub routine checks for the mandatory fields, their data types and maximum length
	also validates valid email entered or not
	Return : True/False
	Input : objFrm ( form object name)
	Programmer : Naveen Sharma
	Dated : 22-05-2002
	Version : 1.0.0
----------------------------------------------------------------------------------------*/
function ValidateForm(objFrm)
{
	var iConventionPos;
	var sChangedName;
	
	for( var i =0; i< objFrm.length;i++)
	{
		
		if(objFrm[i].type=='text' || objFrm[i].type=='textarea' || objFrm[i].type=='select-one' || objFrm[i].type=='select-multiple' || objFrm[i].type=='password')
		{
			if(objFrm[i].type=='text' || objFrm[i].type=='textarea' || objFrm[i].type=='password')
				objFrm[i].value = fnFixSpace(objFrm[i].value);
			
			var objDataTypeHolder = objFrm[i].name.substring(0,3);
		
			if(objFrm[i].name.substring(0,5)=='TREF_' || objFrm[i].name.substring(0,5)=='TNEF_'  || objFrm[i].name.substring(0,5)=='POKR_')
				objDataTypeHolder = objFrm[i].name.substring(0,5);
			if((objFrm[i].type=='select-one' && objFrm[i].options[objFrm[i].selectedIndex].value=='' && objDataTypeHolder=="TR_"))
			{
				sChangedName = objFrm[i].name.substring(3);
				sChangedName = getFormattedmsg(sChangedName);

				
				alert("Please select "+ sChangedName +".");
		
				objFrm[i].focus();
				return false;
				break;
				
				
			}

			if(objFrm[i].type=='password' && objFrm[i].name=='TR_password')
			{
				
						var error = "";
						if (objFrm[i].value.length==0) {
							error = "Please enter password.\n";
							
						} 
						else if (objFrm[i].value.indexOf(" ")!=-1) {
							error = "The password must not contain spaces.\n";
							
						}  else if ((objFrm[i].value.length < 6) || (objFrm[i].value.length > 20)) {
							error = "The password should be only 6-20 characters long. \n";
							
						}  
						 
					   
				if(error)	{
					alert(error);
					objFrm[i].focus();
					return false;
					break;
				}
			}
			if(objFrm[i].type=='password' && objFrm[i].name=='TR_Confirm_Password' && objFrm[i].value!=objFrm.TR_Password.value)
			{
				alert("Password and confirm password fields are not matching.");
				objFrm[i].select();
				return false;
				break;
			}
			if(objFrm[i].type=='password' && objFrm[i].name=='TR_Confirm_New_Password' && objFrm[i].value!=objFrm.TR_New_Password.value)
			{
				alert("New Password and confirm New password fields are not matching.");
				objFrm[i].select();
				return false;
				break;
			}
			if((objDataTypeHolder=="UN_" || objDataTypeHolder=="NN_" ||  objDataTypeHolder=="TR_" || objDataTypeHolder=="IR_" || objDataTypeHolder=="MR_"  )&& (objFrm[i].value==''))
			{	
				sChangedName = objFrm[i].name.substring(3);
				sChangedName = getFormattedmsg(sChangedName)

				alert("Please enter "+ sChangedName.replace("[]", "") +".");
				objFrm[i].focus();
				return false;
				break;
			}
			
			if((objDataTypeHolder=="TREF_" || objDataTypeHolder=="POKR_")  && objFrm[i].value=='')
			{
				sChangedName = objFrm[i].name.substring(5);
				sChangedName = getFormattedmsg(sChangedName);
			
				alert("Please enter "+ sChangedName +".");
				objFrm[i].focus();
				objFrm[i].select();
				return false;
				break;
			}						
			if(objFrm[i].name=='TREF_Confirm_email' && objFrm[i].value!=objFrm.TREF_email.value)
			{
				alert("Email and confirm email fields are not matching.");
				objFrm[i].focus();
				objFrm[i].select();
				return false;
				break;
			}	
			if((objDataTypeHolder=="IR_" || objDataTypeHolder=="MR_" )&& (isNaN(objFrm[i].value)))
			{
				sChangedName = objFrm[i].name.substring(3);
				sChangedName = getFormattedmsg(sChangedName)
				alert("Please enter numeric "+ sChangedName +".");
				objFrm[i].focus();
				objFrm[i].select();
				return false;
				break;
			}
			
			var name_check = /^([a-zA-Z\s])+([\s])*([a-zA-Z\s])*$/;
			if((objDataTypeHolder=="NN_" && !name_check.test(objFrm[i].value) ))
			{					
				sChangedName = objFrm[i].name.substring(3);
				sChangedName = getFormattedmsg(sChangedName)
				alert(sChangedName +" should be in alphabets only");
				objFrm[i].focus();
				objFrm[i].select();
				return false;
				break;
			}
			
			
			var name_check = /^([a-zA-Z\s])+([\s])*([a-zA-Z\s])*$/;
			if(( objDataTypeHolder=="PN_" && objFrm[i].value!=''  && !name_check.test(objFrm[i].value) ))
			{
				sChangedName = objFrm[i].name.substring(3);
				sChangedName = getFormattedmsg(sChangedName)
				alert(sChangedName +" should be in alphabets only");
				objFrm[i].focus();
				objFrm[i].select();
				return false;
				break;
			}
			
			
			if(objDataTypeHolder=="UN_" && objFrm[i].value!='' && objFrm[i].value.indexOf(" ")!=-1)
			{
				sChangedName = objFrm[i].name.substring(3);
				sChangedName = getFormattedmsg(sChangedName)
				alert("Spaces are not allowed in "+ sChangedName +".");
				objFrm[i].focus();
				objFrm[i].select();
				return false;
				break;
			}			

			if((objDataTypeHolder=="IN_" || objDataTypeHolder=="MN_" )&& (isNaN(objFrm[i].value) && objFrm[i].value!='' ))
			{
				sChangedName = objFrm[i].name.substring(3);
				sChangedName = getFormattedmsg(sChangedName)
				alert("Please enter numeric "+ sChangedName +".");
				objFrm[i].focus();
				objFrm[i].select();
				return false;
				break;
			}

			if((objDataTypeHolder=="TREF_" || objDataTypeHolder=="TNEF_" || objDataTypeHolder=="POKR_" ) && objFrm[i].value!='' )
			{
			
				if(objDataTypeHolder=="POKR_"){
					var ln=objFrm[i].value.length;
					var postfix=objFrm[i].value.substr(ln-17,17);	
					if(postfix!="wharton.upenn.edu"){
						alert("Please enter valid email.");
						objFrm[i].focus();
						objFrm[i].select();
						return false;
						break;					
					}
				}
								
				if(!ValidateEMail(objFrm[i].value))
				{
					alert("Please enter valid email.");
					objFrm[i].focus();
					objFrm[i].select();
					return false;
					break;
				}
				
			}
			
			//ValidateNumber(objName)
			if((objDataTypeHolder=="NR_"))
			{
				if(!ValidateNumber(objFrm[i].value))
				{
					objFrm[i].focus();
					return false;
					break;
				}
			}
						
			if(objDataTypeHolder=="PHR")
			{
				var val=objFrm[i].value;
				
				if(val=="")
				{
					alert("Please Enter Phone Number");
					objFrm[i].focus();
					objFrm[i].select();
					return false;
					break;
				}
			}
			//ValidateNumber(objName)
			if((objDataTypeHolder=="NR_"))
			{
				if(!ValidateNumber(objFrm[i].value))
				{
					objFrm[i].focus();
					return false;
					break;
				}
				if(parseFloat(objFrm[i].value)<=0)
				{
					objFrm[i].focus();	
					alert('Price should be greater then 0');
					return false;
				}
			}
			if(objDataTypeHolder=="PHN")
			{
				var val=objFrm[i].value;
				if (val!="")
				{
					for(var j=0; j < val.length;j++)
					{
						if((val.charAt(j)!='(')&&(val.charAt(j)!=')')&&(val.charAt(j)!=' ')&&(val.charAt(j)!="-")&& !((val.charAt(j)>=0)&&(val.charAt(j)<=9)))
						{
							alert("Please enter valid Phone Number");
							objFrm[i].focus();
							objFrm[i].select();
							return false;
							break;
						}
					}
				}				
			}
		}
		

		
		if(objFrm[i].type=='file' && objDataTypeHolder=='FL_' && objFrm[i].value!=''){
				var len=objFrm[i].value.length;
				var ext=objFrm[i].value.substr(len-4,4);
				ext=ext.toLowerCase();
				if(len>0 && ext!='jpeg' && ext!='.jpg' && ext!='.bmp' && ext!='.gif' && ext!='.png' ){							
					alert("Please browse \n jpeg OR jpg OR bmp OR gif OR png \n type only");
					objFrm[i].focus();
					return false;
				} 		
		}		
		if(objFrm[i].type=='file' && objDataTypeHolder=='FE_' && objFrm[i].value!=''){
				var len=objFrm[i].value.length;
				var ext=objFrm[i].value.substr(len-4,4);
				ext=ext.toLowerCase();										
				if(len>0 && ext!='jpeg' && ext!='.jpg' && ext!='exif' && ext!='iptc' && ext!='tiff' && ext!='.tif' && ext!='.bmp' && ext!='.gif' && ext!='.png' && ext!='.pic' ){							
					alert("Please browse \n jpeg OR jpg OR exif OR iptc OR tiff OR tif OR bmp OR gif OR png OR pic OR cel OR cut OR pal OR eps OR ico \n type only");
					objFrm[i].focus();
					return false;
				} 		
		}
// validation for video clips---------------------------------> begin  wmv mov		

		if(objFrm[i].type=='file' && objDataTypeHolder=='VC_' && objFrm[i].value==''){
			alert("Please enter "+sChangedName);
			objFrm[i].focus();
			return false;
		}
		
		if(objFrm[i].type=='file' && objDataTypeHolder=='VC_' && objFrm[i].value!=''){
				var len=objFrm[i].value.length;
				var ext=objFrm[i].value.substr(len-4,4);
				ext=ext.toLowerCase();
				if(len>0 && ext!='.mov' && ext!='.wmv' ){							
					alert("Please browse mov OR wmv type only");
					objFrm[i].focus();
					return false;
				} 		
		}		
		if(objFrm[i].type=='file' && objDataTypeHolder=='VE_' && objFrm[i].value!=''){
				var len=objFrm[i].value.length;
				var ext=objFrm[i].value.substr(len-4,4);
				ext=ext.toLowerCase();										
				if(len>0 && ext!='.mov' && ext!='.wmv' ){							
					alert("Please browse mov OR wmv type only");
					objFrm[i].focus();
					return false;
				} 		
		}
// validation for video clips---------------------------------> end		
				
	}
	return true;
}


function FormatDate(d)
{
		var dd,mm;
		var l;
		l=d.indexOf("/");
		dd=d.substring(0,l);
		d=d.substring(l+1);
		l=d.indexOf("/");
		mm=d.substring(0,l);
		yy=d.substring(l+1);
		
		if (parseInt(dd) < 10)
			dd="0" + dd;
		if (parseInt(mm) < 10)
			mm="0" + mm;
		d= dd + "/" + mm + "/" + yy
		alert(d);
		return d;
		
}

function ValidateImg(objImg, isRequired)
{
	if(isRequired ==1 && objImg.value=='')
	{
		alert("Please enter image.");
		objImg.focus();
		return false;
	}
	if(objImg.value.length!=0)
	{
		if(objImg.value.length<5)
		{
			alert("Please enter valid image.");
			objImg.focus();
			objImg.select();
			return false;
		}
		var iPos = objImg.value.lastIndexOf(".")
		var sExt = objImg.value.substring(iPos);
		if((sExt.toUpperCase()=='.JPEG') || (sExt.toUpperCase()=='.JPG') || (sExt.toUpperCase()=='.GIF') || (sExt.toUpperCase()=='.BMP') )
		{
			return true;
		}
		else
		{
			alert("Please enter valid image.");
			objImg.focus();
			objImg.select();
			return false;
		}
	}
	return true;
}

function ValidateNumber(objName)
{
	//created on: 12th May 2002
	//Programmer: Naveen Sharma
	//Purpose	: This function is used to validate price. 
	//Arguments : Email object
		
	var h;
	var x;
	
	h=objName.length;
	x = objName;
	if (h==0)
	{
		alert("Price Can be numeric only");
		return false;
	}			
	for( i=0;i<h;i++)
	{
		z = x.substring(i,i+1);
		if ( z=="'"||z=='"' || (z >= "a" && z <= "z" ) || (z >= "A" && z <= "Z") )
		{
			alert("Price Can be numeric only");
			return false;
		}			
	}
	jj=x.indexOf(".");
	if (jj != "-1") 
		{
		hh=x.substring(jj);
		ll=hh.length;
		if (ll > 3) 
			{
			alert("Price Can have upto 2 decimal places");
			return false;
			}
		}
	x = objName;
	return true;
	
}

function ValidateNumber(objName)
{
	//created on: 12th May 2002
	//Programmer: Naveen Sharma
	//Purpose	: This function is used to validate email. 
	//Arguments : Email object
		
	var h;
	var x;
	
	h=objName.length;
	x = objName;
	if (h==0)
	{
		alert("Price cannot be left blank");
		return false;
	}			
	for( i=0;i<h;i++)
	{
		z = x.substring(i,i+1);
		if ( z=="'"||z=='"' || (z >= "a" && z <= "z" ) || (z >= "A" && z <= "Z") )
		{
			alert("Price Can be numeric only");
			return false;
		}			
	}
	jj=x.indexOf(".");
	if (jj != "-1") 
		{
		hh=x.substring(jj);
		ll=hh.length;
		if (ll > 3) 
			{
			alert("Price Can have upto 2 decimal places");
			return false;
			}
		}
	return true;
	
}

function getFormattedmsg(sVal)
{
	while(sVal.indexOf("_")!=-1)
	{
		sVal = sVal.replace("_", " ")
	}
	return sVal;
	
}

// Function for cheking the proper Email ID while making login in Classified and Community section
	function valLoginForm(obj)
{

if(ValidateForm(obj))
	{
			if (ValidateEMail(obj.TR_Email_ID.value))
			{
				return true;
			}
			else
			{
				alert("Please enter Email ID in proper format");
				obj.TR_Email_ID.focus();
				return false;			
			}
	}
	return false;
}

function fnDetails(detailpage,iwidth,iheight)
{
	iLeft = parseInt(screen.width)/2-parseInt(iwidth)/2
	iTop = parseInt(screen.height)/2-parseInt(iheight)/2
	window.open(detailpage, "a", "toolbars=0, menubar=0, noresize, scrollbars=yes, left=" + iLeft + ",top=" + iTop + ", width=" + iwidth + ", height=" + iheight)
}


function valform(obj)
{
	
	if(ValidateForm(obj))
	{
			if (ValidateEMail(obj.TR_Email.value))
			{
				obj.submit()
				return true;
			}
			else
			{
				alert("Please enter Email in proper format")
				obj.TR_Email.select()
				return false;			
			}
	}
	return false;
}

	function keyvalid(){
			if(event.keyCode < 45 || event.keyCode > 57){ 
				event.returnValue = false;
			}	
			if(event.which < 45 || event.which > 57){ 
				return false;
			}
	}
	function redirect(opt){				
		if(opt==1){
			window.location="product.php";
		}else if(opt==2){
			window.location="billinfo.php";
		}else if(opt==3){
			window.location="historyview.php";
		}else if(opt==4){
			window.location="cart.php?cls=1";						
		}
	}
function addRowToTable()
{
  var tbl = document.getElementById('tblatributeID');
  var lastRow = tbl.rows.length;  
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);  
  // left cell
  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode(iteration+'.');  
  cellLeft.setAttribute('align','center');    
  cellLeft.appendChild(textNode);
  
  var sizecell = row.insertCell(1);
  var el = document.createElement('input');
  el.setAttribute('type', 'text');

  el.setAttribute('name', 'psize[]');
  el.setAttribute('id', 'sizeid' + iteration);
  el.setAttribute('size', '20');
  el.setAttribute('class', 'inp');  
  sizecell.appendChild(el);

  var pricecell = row.insertCell(2);
  var el = document.createElement('input');
  el.setAttribute('type', 'text');
  el.setAttribute('name', 'pprice[]');
  el.setAttribute('id', 'priceid' + iteration);
  el.setAttribute('size', '10');  
  el.setAttribute('class', 'inp');
  el.onkeypress = keyvalid;
  pricecell.appendChild(el);

  var colorcell = row.insertCell(3);
  var el = document.createElement('input');
  el.setAttribute('type', 'text');
  el.setAttribute('name', 'pcolor[]');
  el.setAttribute('id', 'colorid' + iteration);
  el.setAttribute('size', '20');
  el.setAttribute('class', 'inp');  
  colorcell.appendChild(el);
}
function keyvalid(){
			if(event.keyCode < 45 || event.keyCode > 57){ 
				event.returnValue = false;
			}	
			if(event.which < 45 || event.which > 57){ 
				return false;
			}
}
function removeRowFromTable()
{
  var tbl = document.getElementById('tblatributeID');
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}

function validateRow()
{
    var tbl = document.getElementById('tblatributeID');
    var lastRow = tbl.rows.length - 1;
    var i;
    for (i=1; i<=lastRow; i++) {
		var txtSize = document.getElementById('sizeid' + i);
		var txtPrice = document.getElementById('priceid' + i);
		var txtColor = document.getElementById('colorid' + i);
		  if (txtSize.value.length <= 0 || txtPrice.value.length <= 0 || txtColor.value.length <= 0) {
			alert('Product attributes: -\n\nRow '+ i +' is not filled \nEach cell of row must be filled');
			document.getElementById('sizeid' + i).focus();
			return false;
		  }    
  	}
	return true; 
}

	function popwin(page,iwidth,iheight){
		iLeft = parseInt(screen.width)/2-iwidth/2
		iTop = parseInt(screen.height)/2-iheight/2
		window.open(page, "a", "toolbars=0, menubar=0, noresize, scrollbars=yes, left=" + iLeft + ",top=" + iTop + ", width="+iwidth+", height="+iheight)
	}
function show_tbl(tbl_id){		
		document.getElementById(tbl_id).style.display='';		
}
function hide_tbl(tbl_id){				
		document.getElementById(tbl_id).style.display='none';
}
function hideshowtbl(show_tbl,hide_tbl){		
		document.getElementById(show_tbl).style.display='';
		document.getElementById(hide_tbl).style.display='none';
}
function full_screen_pop_up(theURL,windowname){
	window.open(theURL, windowname, ',type=fullWindow,fullscreen,scrollbars=yes');
}
function backtolist(url){
	window.location=url;
}

function validateDob(){
	var day = document.getElementById('day').value;
	var month = document.getElementById('month').value;
	var year = document.getElementById('year').value;
	if(day!='' || month!='' || year!=''){
			if(day==''){
				alert("Please select day.");
				return false;
			}
			if(month==''){
				alert("Please select month.");
				return false;
			}
			if(year==''){
				alert("Please select year.");
				return false;
			}
	}
	return true;
}

function getById(id){
		return document.getElementById(id);
}

function validateDonate(){
	
		if(getById('how_know').value==''){
				alert("Please select how you know about Yes2funding");
				getById('how_know').focus();
				return false;
		}
		var error = true;
		for(var x=1;x<=4;x++){
				if(getById('pay_type'+x).checked){
					error = false;
				
			}
		}
		if(error){
				alert("Please select pay type");
				return false;
		}else if(getById('pay_type4').checked){
			
			if(getById('other_amount').value==''){
					alert("Please enter other donate amount");
					getById('other_amount').focus();
					return false;
			}
			
		}
		return true;
}
function showMore(val){
		
			for(var x=1;x<=4;x++){
				if(val=='other'){
					getById('other_pay_type'+x).disabled=false;
					getById('other_pay_type1').checked=true;
					getById('other_amount').disabled=false;
							
				}
				else{
					getById('other_amount').disabled=true;
					getById('other_pay_type'+x).disabled=true;
					getById('other_pay_type1').checked=false;
				}
			}
		
}


function validateExtra(){
		
				
				if(getById('acceptBox').checked==false){
					alert("Please select Terms & Conditions.");		
					return false;
				}
				if(getById('agree_type1').checked==false && getById('agree_type2').checked==false){
					alert("Please select one option from agreement below.");				
					return false;
				}
				if(getById('checkEmail').value=='1'){
					alert("Sorry, this email is already in used.Please try other.");				
					return false;
				}
				
		
}
function ValidateChangePassword(){
			
		if (document.getElementById("old_password").value.length==0) {
			alert("Enter old password");
			document.getElementById("old_password").focus();
			return false;
			
		} 
		if (document.getElementById("new_password").value.length==0) {
			alert("Enter new password ");
			document.getElementById("new_password").focus();
			return false;
			
		} 		
		else if (document.getElementById("new_password").value.indexOf(" ")!=-1) {
			alert("The password must not contain spaces");
			document.getElementById("new_password").focus();
			return false;
						
		}  else if ((document.getElementById("new_password").value.length < 6) || (document.getElementById("new_password").value.length > 20)) {
			alert("The password should be only 6-20 characters long");
			document.getElementById("new_password").focus();
			return false;
		}  
		if(document.getElementById("new_password").value!=document.getElementById("confirm_password").value){
			alert(" The new password and confirm password did not match");
			document.getElementById("confirm_password").focus();
			return false;
		}
		if(document.getElementById("new_password").value==document.getElementById("old_password").value){
			alert(" Old password and new password must not be same");
			document.getElementById("new_password").focus();
			return false;
		}
		
		return true;
}
function allAtOnce(val){
		var txt = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="donate_by" value="1">&nbsp;Single donation by credit/debit card<br>';
		txt +='&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="donate_by" value="2">&nbsp;Single donation by PayPal';
	if(val==4)
		document.getElementById('target').innerHTML = txt;
	else
		document.getElementById('target').innerHTML = '';
		
}

function validate_manage_members() {
	var pb=document.manage_members;
	var email_check = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var name_check = /^([a-zA-Z\s])+([\s])*([a-zA-Z\s])*$/;
			
	if((pb.email.value.length >= 0) && (!email_check.test(pb.email.value))) {
		alert("Please enter a valid Email ID");
		pb.email.focus();
		return false;
	}
	if(getById('checkEmail').value=='1'){
		alert("Sorry, this email is already in used.Please try other.");	
		pb.email.focus();
		return false;
	}
	if (pb.pwd.value.length < 6) {
		alert("Please enter a valid password [Minimum 6 characters]");
		pb.pwd.focus();
		return false;
	}
	
	if (pb.pwd.value != pb.cpwd.value) {
		alert("Confirm Password does not match");
		pb.cpwd.focus();
		return false;
	}
	if (pb.title.value==0) {
		alert("Please select your title");
		pb.title.focus();
		return false;
	}
	
	if (pb.firstName.value==0) {
		alert("Please enter your first name");
		pb.firstName.focus();
		return false;
	}
	
	/*if (pb.phone.value==0) {
		alert("Please enter your phone");
		pb.phone.focus();
		return false;
	}
	if (isNaN(pb.phone.value)) {
		alert("Phone should be numeric only");
		pb.phone.focus();
		return false;
	}
	
	if (isNaN(pb.phone.value)) {
		alert("Phone should be numeric only");
		pb.phone.focus();
		return false;
	}
	if (pb.fax.value!='' && isNaN(pb.fax.value)) {
		alert("Fax should be numeric only");
		pb.fax.focus();
		return false;
	}*/
	if (!name_check.test(pb.firstName.value)) {
		alert("First name should be in alphabets only");
		pb.firstName.focus();
		return false;
	}
	
	if (pb.lastName.value==0) {
		alert("Please enter your last name");
		pb.lastName.focus();
		return false;
	}
	if (!name_check.test(pb.lastName.value)) {
		alert("Last name should be in alphabets only");
		pb.lastName.focus();
		return false;
	}
	
	
	
	if (pb.city.value==0) {
		alert("Please enter your billing city");
		pb.city.focus();
		return false;
	}
	
	if (!name_check.test(pb.city.value)) {
		alert("City should be in alphabets only");
		pb.city.focus();
		return false;
	}
	
	
	if (pb.country.value==0) {
		alert("Please select your billing country");
		pb.country.focus();
		return false;
	}
	if (pb.address.value==0) {
		alert("Please enter your billing address");
		pb.address.focus();
		return false;
	}
	
	
	if (pb.cityShip.value==0) {
		alert("Please enter your shipping city");
		pb.cityShip.focus();
		return false;
	}
	if (!name_check.test(pb.cityShip.value)) {
		alert("Shipping City should be in alphabets only");
		pb.cityShip.focus();
		return false;
	}

	
	if (pb.countryShip.value==0) {
		alert("Please select your shipping country");
		pb.countryShip.focus();
		return false;
	}
	if (pb.addressShip.value==0) {
		alert("Please enter your shipping address");
		pb.addressShip.focus();
		return false;
	}
	
}

function validate_login_form() {
	var pb=document.login_form;
	
	if (pb.email.value == 0) {
		alert("Please enter your Email Id ");
		pb.email.focus();
		return false;
	}
	
	if (pb.pwd.value == 0 || pb.pwd.value == "Password") {
		alert("Please enter ypur password");
		pb.pwd.focus();
		return false;
	}	
}


function newsletter_validate() {
	var pb=document.newsletter;
	
	var email_check = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if((pb.email.value.length >= 0) && (!email_check.test(pb.email.value))) {
		alert("Please enter a valid Email ID");
		pb.email.focus();
		return false;
	}
	
	if (pb.name.value == 0 || pb.name.value == "Enter Your Name") {
		alert("Please enter your name");
		pb.name.focus();
		return false;
	}
}
function toggleQuestion(question) {
	if (document.getElementById('q' + question).style.visibility == 'visible') {
		document.getElementById('q' + question).style.visibility = 'hidden';
		document.getElementById('q' + question).style.position = 'absolute';
		document.getElementById('exp_col_' + question).src = 'images/graphic_expand.gif';
	} else {
		document.getElementById('q' + question).style.visibility = 'visible';
		document.getElementById('q' + question).style.position = 'static';
		document.getElementById('exp_col_' + question).src = 'images/graphic_colapse.gif';
	}
}
