// function to check for null values.
function isBlank(s)
{
	  var len,k,flg;
	  flg=true;
	  if(s!=null)
	  {
		len=s.length;
		for(k=0;k<len;k++)
		 {
		  if(s.substring(k,k+1)!=" ")
				flg=false;
		 }
	  }
	 return flg;
}

// function to check for the valid names. Allowed characters are a-z,A-Z,. and space
function isName(str)
{
	//if (str.length < 3)
	//	return false;
	for (var i = 0; i < str.length; i++)
	{
		var ch = str.substring(i, i+1);
		var ch1 = str.substring(i+1, i+2);
		var ch2 = str.substring(i+2, i+3);
		if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch != ".") && (ch != ' ') && (ch != '\''))
		{
			return false;
		}
	}
	return true;
}

function validprice(aElement)
{
	var lsElementValue = aElement.value;
	var lsBuffer1 = "";
	for (var i = 0; i < lsElementValue.length; i++)
	{
		var lsCh = lsElementValue.substring(i, i + 1)
		if (((lsCh >= "0") && (lsCh <= "9")) || (lsCh ==",") || (lsCh == " "))
		lsBuffer1 += lsCh;
		else 
		{
		aElement.value = "";
		alert("Please enter valid numeric value.")
		return false
		}
	}
	return true
}

// function to check for the numbers
function validnum(mnum) 
{
	mlen=mnum.length;
	cnt=0;
	for (var i = 0; i < mlen; i++)	
	{
		if (mnum.substring(i,i+1) != 0) 
		{
			if (!parseInt(mnum.substring(i,i+1)))
				cnt++;
		}
	}
	if ((cnt>0))
		return 0;
	else
		return 1;
}


/* function to check for the float number. Allows 0-9 and a decimal and space */
	function ValidateFloat(aElement)
	{
	var lsElementValue = aElement.value;
	var lsBuffer1 = "";
	for (var i = 0; i < lsElementValue.length; i++)
	{
		var lsCh = lsElementValue.substring(i, i + 1)
		if (((lsCh >= "0") && (lsCh <= "9")) || (lsCh ==".") || (lsCh == " "))
		lsBuffer1 += lsCh;
		else if (lsCh !="%")
		{
		aElement.value = "";
		alert("Please enter valid numeric value.")
		return false
		}
	}
	return true
	}
	
	/* To remove commas from the valid string of numbers (i.e it is used for currency)*/
		function removeCommas(strValue) 
		{
			var objRegExp = /,/g; //search for commas globally
			//replace all matches with empty strings
			return strValue.replace(objRegExp,'');
		}

	/* To add commas to the valid string of numbers (i.e it is used for currency) */
		function addCommas(strValue) 
		{
			var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})'); 
			while(objRegExp.test(strValue)) 
			{
				strValue = strValue.replace(objRegExp, '$1,$2');
			}
			return strValue;
		}
		
		//Function to Check Valid Email Address
function IsInvalidEmail(EMAIL) 
{
	var name;
	var i;
	invalidChars = " /:,;'`?";

	for (i=0; i<invalidChars.length; i++) 
	{	                         // does it contain any invalid characters?        
		badChar = invalidChars.charAt(i);
		if (EMAIL.indexOf(badChar,0) > -1) 
		{
			return true;
		}
	}

	atPos = EMAIL.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) 
	{
		return true;
	}

	if ((atPos + 1) != EMAIL.length)
	{
		if (EMAIL.indexOf("@",atPos+1) != -1) 
		{	// and only one "@" symbol
			return true;
		}
	}

	periodPos = EMAIL.indexOf(".",atPos);
	if (periodPos == -1) 
		{					// and at least one "." after the "@"
		return true;
		}

	if (periodPos+3 > EMAIL.length)	
		{		// must be at least 2 characters after the "."
		return true;
		}
	return false;
}

/* following functions added by sajjad for CYO Rings Module Preload Images */
		
		<!--
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() { //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];}
}
//-->


/* Function added by khushbu to open the popup of send an email to friend
   It is called on the click of the link "Email to a Friend" on the pages throughout the site	 */
function MM_openBrWindow(theURL,winName,features)
{
	window.open(theURL,winName,features);
}


/* Function to open the glossary window on the click of the link "Glossary" in the Left Navigation */
function popup()
{
	introwin= window.open ("../Glossary/Intro.aspx", "mywindow","location=0,status=0,scrollbars=0,width=420,height=320,scrollbars=yes");
	introwin.moveTo(300,300);
}

/* Function to open the glossary window on the click of the link "Glossary" in the Left Navigation on "Appraisals" and "Garding Reports" pages*/
function popupAppr()
{
	introwin= window.open ("Glossary/Intro.aspx", "mywindow","location=0,status=0,scrollbars=0,width=420,height=320,scrollbars=yes");
	introwin.moveTo(300,300);
} 

/* Function to build the url to redirect to "SendAnEmail.aspx" called on the click of the link "Email to a Friend" */
function SendEmailurl(ItemId,LotId)
{
	var theUrl='../Main/SendAnEmail.aspx?itemid='+ ItemId + '&lotid='+ LotId;
	return theUrl;
}

/* Function will redirect the page to the add to wish AddToWishList.aspx with the parameters*/
function SendToCart(ItemID,ForeignKey,SelectedItemSize,Appraisal,CartItemID,CartItemType)
{
	/*	ItemID							------	ItemID	(must)											
		ForeignKey						------	LOTNN (must for diamonds)
		SelectedItemSize				------	(must for rings:Default 6 and chain lenght:Default 18)
		Appraisal						------	ie 1 for true or 0 for false i.e checkbox of appraisal deafualt is 0
		CartItemID						------	Will Be passed only when a change in size is used (must when send from a resizing page)
												deafult = ""
		It will except CartItemType		------	1>BU-for add to cart		2>WI-for wish list	(must)
	
	
		The old url parameter( ie &OLDURL="+window.location ) in the query string send the Curent page URL to be set for the continue shopping button on the shopping cart. 
	
		This fuction will preaper a query string which will redirect the page to AddToWishList.aspx with the respective parameters			
		Sends to AddToWishList with appropriate parameters	
	*/
	
	/*Ref --http://www.i2d.com.au/members/~benmann/javascriptreplace.html--
	Fisrt replace the & ,= ,+ , from the window.location then use this to be sent as the old URL*/
	
	s = new String(window.location);
	s = s.replace(/&/g,"*am*");
	s = s.replace(/=/g,"*eq*");
	s = s.replace(/\+/g,"*pl*");	
	
	/*Fisrt replace the & ,= ,+ , from the window.location then use this to be sent as the old URL*/
	
	//alert("../Cart/AddToWishList.aspx?ItemID="+ItemID+"&ForeignKey="+ForeignKey+"&ItemSizeTo="+SelectedItemSize+"&Appraisal="+ Appraisal +"&CID="+CartItemID+"&CIT="+CartItemType+"&OLDURL="+s);	
	document.location.href = "../Cart/AddToWishList.aspx?ItemID="+ItemID+"&ForeignKey="+ForeignKey+"&ItemSizeTo="+SelectedItemSize+"&Appraisal="+ Appraisal +"&CID="+CartItemID+"&CIT="+CartItemType+"&OLDURL="+s;
}