function ltrim ( s )
{
        return s.replace( /^\s*/, "" )
}

function rtrim ( s )
{
        return s.replace( /\s*$/, "" );
}

function trim ( s )
{
        return rtrim(ltrim(s));
}

function isPropermail(string)
{

   if (!string) return false;
   var iChars = "@";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
}

function isProperdot(string)
 {

	if (!string) return false;
	var iChars = ".";

	for (var i = 0; i < string.length; i++) {
	   if (iChars.indexOf(string.charAt(i)) != -1)
	      return false;
   }
   return true;
 }
 
function chkthis(sCat,sSort,passedObject)
{
 	form1.action ="ItemList.asp?CatId=" + sCat + "&Sort=" + sSort + "&items=" + passedObject.value;	
 	form1.submit();
}

function isProperm(string)
{

	if (!string) return false;
	var iChars = "*|+,\":<>[]{}`\';()&$#%";

	for (var i = 0; i < string.length; i++) {
	   if (iChars.indexOf(string.charAt(i)) != -1)
	      return false;
   }
   return true;
}

function isNotBlank(strBlank)
{
	if ((strBlank == null) || (strBlank == "")) 
	{	
		//alert(blank);
		return false;
	}	
	for (var i=0; i< strBlank.length; i++) 
	{
		var c = strBlank.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t'))
			return true;
	}
	return true; 
	
}

function isEmpty(s) {   

    return ((s == null) || (s.length == 0))

}

function isDigit (c) { 

    return ((c >= "0") && (c <= "9"))

}


function isPositiveIntegerWithoutDec (s) {   

    var i;

    if (isEmpty(s)) 
        if (isPositiveInteger.arguments.length == 1) {
			return defaultEmptyOK;
		} else {
			return (isPositiveInteger.arguments[1] == true);
		} 
	
	if(s<0) {
        return false;
    }

    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (!isDigit(c)) 
        	{
        		return false;
        	}
    }
  
    

    // All characters are numbers.
    return true;
}


function SendEmail()
{
	window.open("TellaFriend.asp?ItemHeaderId="+ window.document.forms[0].ItemHeaderId.value + "&ItemId=" + window.document.forms[0].ItemId.value,"TellaFriend","toolbar=0,menubar=0,width=700,height=500");
	//window.document.forms[0].action="TellaFriend.asp";
	//window.document.forms[0].target="_blank";
	//window.document.forms[0].submit();
}

function CheckEmail()
{
	if(isNotBlank(trim(document.forms[0].txtToEmail.value))==false)
	{
	 alert(PromptEmailTo);
	 document.forms[0].txtToEmail.focus();
	 return false;
	}

	if(isNotBlank(trim(document.forms[0].txtFromEmail.value))==false)
	{
	 alert(PromptEmailFrom);
	 document.forms[0].txtFromEmail.focus();
	 return false;
	}
	
	if(isNotBlank(trim(document.forms[0].txtToEmail.value))==true)
	{
		var ToAddrArray = new Array();
		ToAddrArray = document.forms[0].txtToEmail.value.split(",");
		if(ToAddrArray.length > 10)
		{
			alert(MaxEmailAddr);
			document.forms[0].txtToEmail.focus();
			return false;
		}
		for(i=0;i<ToAddrArray.length;i++)
		{
			if (CheckEmailFormat(ToAddrArray[i])==false)
			{
			 document.forms[0].txtToEmail.focus();
			 return false;
			}
		}
	}
	
	if(isNotBlank(trim(document.forms[0].txtFromEmail.value))==true)
	{
		if (CheckEmailFormat(document.forms[0].txtFromEmail.value)==false)
		{
		 document.forms[0].txtFromEmail.focus();
		 return false;
		}
	}	
	
	if(isNotBlank(trim(document.forms[0].txtMsg.value))==true)
	{
		if(document.forms[0].txtMsg.value.length > 100)
		{
			alert(PromptMsgLen);
			document.forms[0].txtMsg.focus();
			return false;
		}
	}
	
	document.forms[0].action="TellaFriend.asp?ItemHeaderId="+ window.document.forms[0].ItemHeaderId.value + "&ItemId=" + window.document.forms[0].ItemId.value;
	document.forms[0].SubmitFlag.value=1;
	document.forms[0].submit();
}

function CheckEmailFormat(email)
{
	if (isPropermail(email) == true) 
	{
		alert(InvalidEmailFormat);
		return false;
	}
	else if (isProperdot(email) == true)  
	{
		alert(InvalidEmailFormat);
		return false;
	}
	return true;
}

function fillItemId(val)
{
	//alert(val);
	
	ItemId = val.substring(0,val.indexOf("~"));
	//alert(ItemId); 
	qty = val.substring(val.indexOf("~")+1);
	
	document.forms[0].ItemId.value=ItemId;
	document.forms[0].hdnQty.value=qty;
}

function AddtoBag(chkItems)
{
	/*if(isNotBlank(trim(document.forms[0].txtQty.value))==false)
	{
		alert(PromptQty);
		document.forms[0].txtQty.focus();
		return false;
	}
	else
	{
	  if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtQty.value))==false)
	  {
		alert(InvalidQtyFormat);
		document.forms[0].txtQty.focus();
		return false;
	  }
	  if(trim(document.forms[0].txtQty.value) <= 0)
	  {
		alert(InvalidQtyFormat);
		document.forms[0].txtQty.focus();
		return false;
	  }
	}*/
	
	var nCheck;
    nCheck = "";
    var arr = new Array();
    boolCheck=false;
    if(chkItems!="")
	{
		arr = chkItems.split(",");				  
	}
	
	
	
	for (var i=0;i<document.forms[0].elements.length;i++)
	{
		var e = document.forms[0].elements[i];
		if (e.type=='checkbox')
		{
			if(e.checked)
			{
				boolCheck=true;
				
			}
			
		}		
	}
	
	if(!boolCheck)
	{
		alert(PromptAdd);
		return false;
	}
	
	var dupCheck=true;
	
	for (var i=0;i<document.forms[0].elements.length;i++)
	{
		var e = document.forms[0].elements[i];
		if (e.type=='checkbox')
		{
			if(e.checked)
			{
				//alert(e.value);
				if(arr.length>0)
				{
				  for(var j=0;j<arr.length;j++)
				  {
				    var pos = arr[j].indexOf("~");
				    var ItemId = arr[j].substring(0,pos);
				    //alert("item: "+ItemId);
				    
					if(parseInt(e.value)==parseInt(ItemId))
					{
						var id=document.getElementById("sp"+e.value);
						var isize=id.innerHTML;
						alert(InvlidAddItem + " '" + document.forms[0].hdnItemName.value + "' of size " + isize);
						e.checked=false;
						dupCheck = false;			
					}
				  }
				}
			}
		}
	}
	
	if(!dupCheck)
	{
		
		return false;
	}
	
			
	document.forms[0].action="ItemDetail.asp"
	document.forms[0].submitFlag.value=1;
	document.forms[0].submit();
}

function BacktoShop(catId)
{
 document.location.href="ItemList.asp?CatId=" + catId + "&Sort=P";	
}

function RemoveItems()
{
    var nCheck;
    nCheck = "";
    boolCheck=false;
	for (var i=0;i<document.forms[0].elements.length;i++)
	{
		var e = document.forms[0].elements[i];
		if (e.type=='checkbox')
		{
			if(e.checked)
			{
				boolCheck=true;
			}
			else
			{
				nCheck = nCheck + e.value + ",";
			}
		}		
	}
	
	if(!boolCheck)
	{
		alert(PromptRemove);
		return false;
	}

	if(nCheck!="")
		nCheck = nCheck.substring(0,nCheck.length-1);
	
	document.forms[0].Items.value=nCheck;
	
	
	document.forms[0].action="AddToBag.asp"
 	document.forms[0].submitFlag.value=1;
	document.forms[0].submit();
}

function CheckLogin(Uid)
{
  if(Uid=="")
  {
	document.location.href="https://www.glamourcloset.com/closet/asp/CheckLogin.asp";
	//document.location.href="http://www.juventustech.com/closet/asp/CheckLogin.asp";
  }
  else
  {
	document.location.href="https://www.glamourcloset.com/closet/asp/OrderSummary.asp?Act=R";
	//document.location.href="http://www.juventustech.com/closet/asp/OrderSummary.asp?Act=R";
  }
}

function GoRegister()
{
	document.location.href="Register.asp"
}

function CheckUIDPWD()
{
  	if(isNotBlank(trim(document.forms[0].txtEmail.value))==false)
	{
		alert(PromptUID);
		document.forms[0].txtEmail.focus();
		return false;
	}
	if (CheckEmailFormat(document.forms[0].txtEmail.value)==false)
	{
	 document.forms[0].txtEmail.focus();
	 return false;
	}
	if(isNotBlank(trim(document.forms[0].txtPWD.value))==false)
	{
		alert(PromptPWD);
		document.forms[0].txtPWD.focus();
		return false;
	}
	
	//document.forms[0].action="CheckLogin.asp"
	document.forms[0].submitFlag.value=1;
	document.forms[0].submit();
}

function CheckRegisterInfo()
{
    if(isNotBlank(trim(document.forms[0].txtBFN.value))==false)
	{
		alert(PromptBFN);
		document.forms[0].txtBFN.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtBLN.value))==false)
	{
		alert(PromptBLN);
		document.forms[0].txtBLN.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtBAddr.value))==false)
	{
		alert(PromptBAddr);
		document.forms[0].txtBAddr.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtBCity.value))==false)
	{
		alert(PromptBCity);
		document.forms[0].txtBCity.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtBState.value))==false)
	{
		alert(PromptBState);
		document.forms[0].txtBState.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtBZip.value))==false)
	{
		alert(PromptBZip);
		document.forms[0].txtBZip.focus();
		return false;
	}
	if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtBZip.value))==false)
	{
	  alert(InvalidBZip);
	  document.forms[0].txtBZip.focus();
	  return false;
	}
	if(isNotBlank(trim(document.forms[0].txtDPhone.value))==false)
	{
		alert(PromptBPhone);
		document.forms[0].txtDPhone.focus();
		return false;
	}
	if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtDPhone.value))==false)
	{
	  alert(InvalidPhone);
	  document.forms[0].txtDPhone.focus();
	  return false;
	}
	if(isNotBlank(trim(document.forms[0].txtEPhone.value))==true)
	{
		if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtEPhone.value))==false)
		{
		  alert(InvalidPhone);
		  document.forms[0].txtEPhone.focus();
		  return false;
		}
	}
	if(isNotBlank(trim(document.forms[0].txtEmail.value))==false)
	{
		alert(PromptBEmail);
		document.forms[0].txtEmail.focus();
		return false;
	}
	if (CheckEmailFormat(document.forms[0].txtEmail.value)==false)
	{
	 document.forms[0].txtEmail.focus();
	 return false;
	}
	/*
	//Shipping parameters
	if(isNotBlank(trim(document.forms[0].txtSFN.value))==false)
	{
		alert(PromptSFN);
		document.forms[0].txtSFN.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtSLN.value))==false)
	{
		alert(PromptSLN);
		document.forms[0].txtSLN.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtSAddr.value))==false)
	{
		alert(PromptSAddr);
		document.forms[0].txtSAddr.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtSCity.value))==false)
	{
		alert(PromptSCity);
		document.forms[0].txtSCity.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtSState.value))==false)
	{
		alert(PromptSState);
		document.forms[0].txtSState.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtSZip.value))==false)
	{
		alert(PromptSZip);
		document.forms[0].txtSZip.focus();
		return false;
	}*/
	
	if(isNotBlank(trim(document.forms[0].txtSZip.value))==true)
	{
		if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtSZip.value))==false)
		{
		  alert(InvalidBZip);
		  document.forms[0].txtSZip.focus();
		  return false;
		}
	}	
	//document.forms[0].action="Register.asp"
 	document.forms[0].submitFlag.value=1;
	document.forms[0].submit();
	
}

function SaveProfile(sAct,UId)
{
   var hd1=	window.open("SaveProfile.asp?Act="+ sAct + "&UId=" + UId,"SaveProfile","toolbar=0,menubar=0,width=700,height=500");
   window.opener="SaveProfile";
   hd1.focus();
}

function CheckSubmitProfile(UId)
{
	if(isNotBlank(trim(document.forms[0].txtEmail.value))==false)
	{
		alert(PromptUID);
		document.forms[0].txtEmail.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtPWD.value))==false)
	{
		alert(PromptPWD);
		document.forms[0].txtPWD.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtCPWD.value))==false)
	{
		alert(PromptCPWD);
		document.forms[0].txtCPWD.focus();
		return false;
	}
	if (CheckEmailFormat(document.forms[0].txtEmail.value)==false)
	{
	 document.forms[0].txtEmail.focus();
	 return false;
	}
	
	if(document.forms[0].txtPWD.value!=document.forms[0].txtCPWD.value)	
	{
		alert(InvalidCPWD);
		document.forms[0].txtCPWD.focus();
		return false;
	}
	
	document.forms[0].action="SaveProfile.asp?UId=" + UId
 	document.forms[0].submitFlag.value=1;
	document.forms[0].submit();
}

function Openwin(Img,ImgTp)
{
  //alert(Img);
  window.open("ShowImage.asp?ImgTp=" + ImgTp + "&ImgName=" + escape(Img),"ItemImage","menubar=0,toolbar=0,width=500,height=500,scrollbars=1");
}

function OpenHallwin(Img,ImgTp,ImgDesc)
{
  //alert(Img);
  window.open("ShowImage.asp?ImgDesc=" + ImgDesc + "&ImgTp=" + ImgTp + "&ImgName=" + Img,"ItemImage","menubar=0,toolbar=0,width=500,height=500,scrollbars=1");
}

function refreshOpener()
{
 document.location.href="OrderSummary.asp?Act=R"
}

function chkpromotion()
{
	if(isNotBlank(trim(document.forms[0].txtpromotion.value))==false)
	{
		alert("Please enter 'Promotional Offer Code' to proceed!");
		document.forms[0].txtpromotion.focus();
		return false;
	}
	
	document.forms[0].action="ordersummary.asp?Act=" + document.forms[0].txtact.value;
	document.forms[0].promotion.value=1;
	document.forms[0].submit();
}

function PurchaseItems()
{
	var Mon;
	var Yr; 
	var crno;
	Mon = parseFloat(document.forms[0].txtExpMon.value);
	Yr = parseInt(document.forms[0].txtExpYr.value);
	crno = trim(document.forms[0].txtCrNo.value);

	if(document.forms[0].lstPublicity.value=="-1")
	{
		alert(PromptPublicity);
		document.forms[0].lstPublicity.focus();
		return false;
	}

	if(isNotBlank(trim(document.forms[0].txtCrNo.value))==false)
	{
		alert(PromptCrNo);
		document.forms[0].txtCrNo.focus();
		return false;
	}
	
	if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtCrNo.value))==false)
	{
	  alert(InvalidCrNo);
	  document.forms[0].txtCrNo.focus();
	  return false;
	}

	if(document.forms[0].lstCrType.value=="Master Card" || document.forms[0].lstCrType.value=="Visa")
	{
		if(crno.length != 16)
		{
		  alert(InvalidCrNo);
		  document.forms[0].txtCrNo.focus();
		  return false;
		}
	}
	else if(document.forms[0].lstCrType.value=="American Express")
	{
		if(crno.length != 15)
		{
		  alert(InvalidCrNo);
		  document.forms[0].txtCrNo.focus();
		  return false;
		}
	}
	
	if(isNotBlank(Yr)==false)
	{
		alert(PromptCrYr);
		document.forms[0].txtExpYr.focus();
		return false;
	}
	
	
	if(isPositiveIntegerWithoutDec(Mon)==false)
	{
	  alert(InvalidCrMon);
	  document.forms[0].txtExpMon.focus();
	  return false;
	}
	if(isPositiveIntegerWithoutDec(Yr)==false)
	{
	  alert(InvalidCrYr);
	  document.forms[0].txtExpYr.focus();
	  return false;
	}
	
	if(Yr.length < 4)
	{
		alert(InvalidCrYrLen);
		document.forms[0].txtExpYr.focus();
		return false;
	}
	if(parseInt(Yr) <= 0)
	{
	  alert(InvalidCrYr);
	  document.forms[0].txtExpYr.focus();
	  return false;
	}
	
	sDate = new Date();
	CurrMon = sDate.getMonth();
	CurrYr = sDate.getYear();
	CurrMon = parseInt(CurrMon) + 1;
		
	if(parseInt(Yr) < parseInt(CurrYr))
	{
		alert(InvalidMonYr);
		document.forms[0].txtExpYr.focus();
		return false;
	}	 
	else if(parseInt(Yr) == parseInt(CurrYr))
	{
		if((Mon) < parseInt(CurrMon))
		{
			alert(InvalidMonYr);
			document.forms[0].txtExpMon.focus();
			return false;
		}
	}
		
	document.forms[0].action="ConnectPaymentGateway.asp"
	document.forms[0].submit();
} 

function checkQty(ths)
{
	//alert(document.forms[0].hdnQty.value);
	if(isNotBlank(trim(ths.value))==true)
	{
		if(parseInt(trim(ths.value)) > parseInt(document.forms[0].hdnQty.value))
		{
			alert(InvalidQtyVal + document.forms[0].hdnQty.value);
			ths.focus();
			return false;
		}
	}
}  

function checkFPWD()
{
	if(isNotBlank(trim(document.forms[0].txtEmail.value))==false)
	{
		alert(PromptUID);
		document.forms[0].txtEmail.focus();
		return false;
	}
	if (CheckEmailFormat(document.forms[0].txtEmail.value)==false)
	{
	 document.forms[0].txtEmail.focus();
	 return false;
	}
	
	window.open("ForgotPWD.asp?Email=" + window.document.forms[0].txtEmail.value,"ForgotPWD","toolbar=0,menubar=0,left=100,top=200,width=600,height=300");
}

function DoSearch()
{
  if(isNotBlank(trim(document.forms[0].txtitemno.value))==false)
  {
	
  	if(document.forms[0].lstPrice.value=="-1" && document.forms[0].lstSize.value=="-1" && document.forms[0].lstColor.value=="-1")
  	{
		alert(SelectCriteria);
		document.forms[0].lstPrice.focus();
		return false;
  	}
  }
  else
  {
  	if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtitemno.value))==false)
	{
		alert(InvalidItemNo);
		document.forms[0].txtitemno.focus();
		return false;
	}
  }
  
  document.forms[0].action="SearchItemList.asp"
  document.forms[0].submit();
}

function clicklink(Act,cpage)
{
  document.forms[0].action="SearchItemList.asp?Sort=" + Act + "&cpage=" + cpage
  document.forms[0].submit();
}

/* For Account Summary */
function CheckEditAccInfo()
{
	if(isNotBlank(trim(document.forms[0].txtBFN.value))==false)
	{
		alert(PromptFN);
		document.forms[0].txtBFN.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtBLN.value))==false)
	{
		alert(PromptLN);
		document.forms[0].txtBLN.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtEmail.value))==false)
	{
		alert(PromptBEmail);
		document.forms[0].txtEmail.focus();
		return false;
	}
	if (CheckEmailFormat(document.forms[0].txtEmail.value)==false)
	{
	 document.forms[0].txtEmail.focus();
	 return false;
	}
	if(isNotBlank(trim(document.forms[0].txtPwd.value))==false)
	{
		alert(PromptPWD);
		document.forms[0].txtPwd.focus();
		return false;
	}
	if(isNotBlank(trim(document.forms[0].txtCPwd.value))==false)
	{
		alert(PromptCPWD);
		document.forms[0].txtCPwd.focus();
		return false;
	}
	if(document.forms[0].txtPwd.value!=document.forms[0].txtCPwd.value)	
	{
		alert(InvalidCPWD);
		document.forms[0].txtCPwd.focus();
		return false;
	}
	window.document.forms[0].submitFlag.value='1';
	window.document.forms[0].submit();
}

function CheckEditAddrInfo(type)
{
	if(type=="B")
	{
		if(isNotBlank(trim(document.forms[0].txtBFN.value))==false)
		{
			alert(PromptBFN);
			document.forms[0].txtBFN.focus();
			return false;
		}
		if(isNotBlank(trim(document.forms[0].txtBLN.value))==false)
		{
			alert(PromptBLN);
			document.forms[0].txtBLN.focus();
			return false;
		}
		if(isNotBlank(trim(document.forms[0].txtBAddr.value))==false)
		{
			alert(PromptBAddr);
			document.forms[0].txtBAddr.focus();
			return false;
		}
		if(isNotBlank(trim(document.forms[0].txtBCity.value))==false)
		{
			alert(PromptBCity);
			document.forms[0].txtBCity.focus();
			return false;
		}
		if(isNotBlank(trim(document.forms[0].txtBState.value))==false)
		{
			alert(PromptBState);
			document.forms[0].txtBState.focus();
			return false;
		}
		if(isNotBlank(trim(document.forms[0].txtBZip.value))==false)
		{
			alert(PromptBZip);
			document.forms[0].txtBZip.focus();
			return false;
		}
		if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtBZip.value))==false)
		{
		  alert(InvalidBZip);
		  document.forms[0].txtBZip.focus();
		  return false;
		}
		if(isNotBlank(trim(document.forms[0].txtDPhone.value))==false)
		{
			alert(PromptBPhone);
			document.forms[0].txtDPhone.focus();
			return false;
		}
		if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtDPhone.value))==false)
		{
		  alert(InvalidPhone);
		  document.forms[0].txtDPhone.focus();
		  return false;
		}
	}
	else
	{
		if(isNotBlank(trim(document.forms[0].txtSZip.value))==true)
		{
			if(isPositiveIntegerWithoutDec(trim(document.forms[0].txtSZip.value))==false)
			{
			  alert(InvalidSZip);
			  document.forms[0].txtSZip.focus();
			  return false;
			}
		}
	}
	
	window.document.forms[0].submitFlag.value='1';
	window.document.forms[0].submit();
} 

function Addemail(email)
{
	if (isPropermail(email) == true) 
	{
		alert(InvalidEmailFormat);
		return false;
	}
	else if (isProperdot(email) == true)  
	{
		alert(InvalidEmailFormat);
		return false;
	}
	document.forms[0].action="addemail.asp?from=A";
	//document.forms[0].submit();
	return true;	
}

function AddemailH(email)
{
	if (isPropermail(email) == true) 
	{
		alert(InvalidEmailFormat);
		return false;
	}
	else if (isProperdot(email) == true)  
	{
		alert(InvalidEmailFormat);
		return false;
	}
	document.forms[0].action="../asp/addemail.asp?from=A";
	//document.forms[0].submit();
	return true;	
}
