// JavaScript Document
//to work paging in proper manne 


function frmsubmit(pageval)
{
	document.frmlist.page.value = pageval;
	document.frmlist.submit();
}

//to update product count on header 
function UpdateProductCount(num_product){
	document.getElementById('totitem_div').innerHTML=num_product ;	
}

			
//to check wheather a radio button  is selected or not
function checkRadio (frm,groupname) {
 var radios = document[frm].elements[groupname];
 for (var i=0; i <radios.length; i++) {
  if (radios[i].checked) {
   return true;
  }
 }
 return false;
} 


//To validate integers
function IsNumeric(strString)

		   //  check for valid numeric strings 

		   {
			   var strValidChars = "0123456789";
			   var strChar;
			   var blnResult = true;
			   if (strString.length == 0) return false;
			   //  test strString consists of valid characters listed above
			   for (i = 0; i < strString.length && blnResult == true; i++)
		      {
			      strChar = strString.charAt(i);
			      if (strValidChars.indexOf(strChar) == -1)
		         {	
        			 blnResult = false;
		         }
      		}
		   return blnResult;
		  }


//To avoid spaces
whiteSpace = " \r\n\t\f";
function isSpaces(str){
	
	str += "";
	//Make sure str is a string
	startPos = 0; //Note: if 0 length string startPos will be 0
	endPos = str.length-1; //Note: if 0 length string endPos will be -1
	if (whiteSpace.indexOf(str.charAt(startPos))>=0)
	{
		return true;
	}
	else
	if (whiteSpace.indexOf(str.charAt(endPos))>= 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//To avoid blanks
function isblank(testStr) 
  { 
  	if (testStr.length == 0) // nothing entered? 
	 return true 
	for (var i = 0; i <= testStr.length-1; i++) // all spaces? 
	 if (testStr.charAt(i)!= " ") 
	  return false ;
      return true ;
  } 
	
function isAlpha(id)
	{
		
		if (id.match(/^[a-zA-Z\s]+$/))
		{
		return true;
		}
		else
		{
		return false;
		} 
	}

//To validate phone number
function IsUSPhoneNumber(objdata)
{

	if(!(/^\d{3}-\d{3}-\d{4}$/).test(objdata.value))
	{
	return true;
	}
	else
	return false;

}

function isEmail(str)
{
		var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
       return regex.test(str);
}


function checkEmailAddress(mailids)
		{
			var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'
,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al',
'.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb',
'.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs',
'.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci',
'.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de',
'.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et',
'.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh',
'.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy',
'.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io',
'.iq','.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk',
'.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg','.mh','.mk',
'.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw',
'.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np',
'.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm',
'.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rw','.ru','.sa',
'.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn',
'.so','.sr','.st','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj',
'.tk','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug',
'.uk','.um','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu',
'.ws','.wf','.ye','.yt','.yu','.za','.zm','.zw');

		var mai = mailids;
		var val = true;
		var beforeat="";
		var afterat1="";
		var afterat="";
		var afterat2="";

		var dot=mai.lastIndexOf(".");
		var con=mai.substring(dot, mai.length);
		con=con.toLowerCase();
		con=con.toString();
		//alert(con);
		for(var i=0;i<(arr.length);i++)
		{
			if(con == arr[i])
			{
				val=true;
				break;
			}
			else
			{
				val=false;
			}
		}

		var att=mai.lastIndexOf("@");
		beforeat=mai.substring(0,att);
		beforeat=beforeat.toLowerCase();
		beforeat=beforeat.toString();
		var asci1=beforeat.charCodeAt(0);

		afterat1=mai.substring(att+1, dot);
		afterat1=afterat1.toLowerCase();
		afterat1=afterat1.toString();

		afterat2=mai.substring(att+1, mai.length);
		afterat2=afterat2.toLowerCase();
		afterat2=afterat2.toString();

		var bool = false;
		var dot1="";
		var con1="";
		if(afterat1.indexOf(".")!=-1)
		{
			dot1=afterat1.lastIndexOf(".");
			con1=afterat1.substring(dot1, afterat1.length);
			con1=con1.toLowerCase();
			con1=con1.toString();	
			//alert(con1);
			for(var j=0;j<(arr.length);j++)
			{
				if(con1 == arr[j])
				{
					val=true;
					break;
				}
				else
				{
					val=false;
				}
			}	
			//alert(val)
			afterat=afterat1.substring(0, dot1);
			afterat=afterat.toLowerCase();
			afterat=afterat.toString();	
	
			var st = afterat2.substring(afterat1.length);
			if(st.length>3)
			bool = true;
	
		}
		else
		{
			afterat=afterat1;
		}

		if(beforeat=="" || afterat=="" || beforeat.length>30)
			val=false;
		if(beforeat.indexOf("..")!=-1)
			val=false;
			//alert(beforeat.substring(beforeat.length-1,beforeat.length));
		if(beforeat.substring(beforeat.length-1,beforeat.length)==".")
    		val = false;

		if(afterat2.length>64 || afterat.length<2)
			val=false;
		if(bool==true)	
			val=false;
		if((afterat.charCodeAt(0))==45 || (afterat.charCodeAt(afterat.length-1))==45)
			val=false;

		if(val==true)
		{
			if(asci1 > 47 && asci1 < 58)
				val=false;
		
			if(asci1 < 48 || asci1 > 57)
			{		
				for(var i=0; i<=beforeat.length-1; i++)
				{
					var asci2=beforeat.charCodeAt(i);		
					if((asci2<=44 || asci2==47) || (asci2>=58 && asci2<=94) || (asci2==96) || (asci2>=123 && asci2<=127))
					{
						val=false;
						break;
					}
				}
			
				for(var j=0; j<=afterat.length-1; j++)
				{				
					var asci3=afterat.charCodeAt(j);			
					if((asci3<=44) || (asci3==46) || (asci3==47) || (asci3>=58 && asci3<=96) || (asci3>=123 && asci3<=127))
					{
						val=false;
						break;
					}
				}	
			}
		}
		if(val==false)
		{	
			return true;
		}
		else
		{
			return false;
		}
	}

	function isValidURL(url)
	{
	
		//var RegExp = /^((ftp|Http|HTTP|https?):\/\/)+((www|WWW\.))?([a-zA-Z0-9\-]{3,})+((.+[A-Za-z]{2,}))+((.+[a-zA-Z]{2,3})?)$/;
		//var RegExp = /^(ftp|Http|HTTP|https?):\/\/(www|WWW\.)?[a-zA-Z0-9\-]{3,}\.[A-Za-z]{2,}\.[a-z]{2,3}$/;
		// var v = new RegExp();
    	// v.compile("^[http|HTTP|ftp|FTP|https]+://");
		var RegExp =/^((ftp|Http|HTTP|https?):\/\/)+((www|WWW\.))?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    	if(RegExp.test(url))
		{
        	return false;
    	}
		else
		{
        	return true;
    	}
	}
function ToggleWomenImage(){
	document.getElementById('women_selection_false').style.display='none';		
	document.getElementById('women_selection_true').style.display='inline';			
}

//create a xmlhttprequestobject
function createHttpObject(){
	if (window.XMLHttpRequest)
		req = new XMLHttpRequest();
	else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return req;
}
function showhide(id)
{
	var display=document.getElementById(id).style.display; 
	if (display=='none')
	{
		document.getElementById(id).style.display= 'inline';
	}
	else
	{
		document.getElementById(id).style.display= 'none';
	}
}
function isInt(num)
{
	var charpos = num.search("[^0-9]");
	if(num.length > 0 && charpos >= 0)
	return false;
	else
	return true;
}
function open_window(link1,w,h) //opens new window
{
	var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
	wishWin = window.open(link1,'wishWin',win);
}
//round a number up to  given place
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

//round a number up to  given place
function roundOffNumber(num, dec) {
	var result = Math.round(num*10)/10;
	return result;
}

function ShowHideDiv(divid, disp)    
{
	if (disp){	
		if(document.getElementById(divid+'_gift')!=null){
			document.getElementById(divid+'_gift').style.display='';
		}
		if(document.getElementById(divid+'_card')!=null){
			document.getElementById(divid+'_card').style.display='';
		}
		document.getElementById('minus_'+divid).style.display=''; 
		document.getElementById('add_'+divid).style.display='none'; 
	}else{
		if(document.getElementById(divid+'_card')!=null){	
			document.getElementById(divid+'_card').style.display='none';
		}
		if(document.getElementById(divid+'_gift')!=null){
			document.getElementById(divid+'_gift').style.display='none';
		}
		//document.getElementById(divid).style.display='none';
		document.getElementById('minus_'+divid).style.display='none';
		document.getElementById('add_'+divid).style.display='';	
	}	
}

// Change buttons on mouseover function on landing page
function changeImage(imgid,cimg){
	//alert(imgid);
	document.getElementById(imgid).src=cimg;
//	alert(document.getElementById(imgid).src);
}

/*function SetCookie1(theme) {
	/* var today = new Date();
	 var expire = new Date();
	 if (nDays==null || nDays==0) nDays=1;
	 expire.setTime(today.getTime() + 3600000*24*nDays);
	 document.cookie = cookieName+"="+escape(cookieValue)
	 + ";expires="+expire.toGMTString();
	 alert( document.cookie);
	 window.location.reload() ;*/
/*	 alert(theme);
  	 window.location.href='forcookies/'+theme;
}
*/
function SetCookie(theme){
		document.login.action='forcookies/'+theme;
		document.login.submit();
}
/*function SetTheme(theme) {
	window.location.href='http://gwl22/spritz/forcookies/'+theme;
 }*/