var whitespace = " \t\n\r";
var defaultEmptyOK = false;
var NS4 = (document.layers) ? true : false;
var today = new Date(); 
var zero_date = new Date(0,0,0); 
today.setTime(today.getTime() - zero_date.getTime()); 
var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000)); 

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}


function isWhitespace (s)

{   
	var i;

    if (isEmpty(s)) return true;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
		
    if (isWhitespace(s)) return false;
	
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
	
}

function isDigit (c)
{  
	return ((c >= "0") && (c <= "9"))
}

function isInteger (s)

{  
	var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }
    return true;
}

function goToPage(url)
{
	window.location.href=url;
}

function openPage(url)
{
	window.open(url,"_blank","width=700,height=600,scrollbars=1,resizable=1");
}

function goToPage1(url)
{
	window.open(url,"_blank","");
}

function openWindow(str){
	url='showpic.asp?pic=' + str;
	window.open(url,"my_new_window", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes");

}

function showShortProdSetails(Str)
{
	window.open("WishList_Product_Details.asp?sID=" + Str,"_blank","width=650,height=500,scrollbars=1,resizable=1");
}

function showUpdateShortProdSetails(Str, ID)
{
	window.open("WishList_Product_Details_Update.asp?sID=" + Str + "&wID=" + ID ,"_blank","width=650,height=500,scrollbars=1,resizable=1");
}

function checkForEnter(event, Str)
{     
    var code = 0;
    
    if (NS4)
        code = event.which;
    else
        code = event.keyCode;
    if (code==13)
        eval(Str);
}

function DoSearch()
{
	SearchForm.submit();
}

function ClientFormact()
{
	if(ClientForm.txtFirstName.value == "")
	{
		alert("Please enter First Name.");
		ClientForm.txtFirstName.focus();
	}
	else if(ClientForm.txtLastName.value == "")
	{
		alert("Please enter Last Name.");
		ClientForm.txtLastName.focus();
	}
	else if(ClientForm.txtEmail.value == "")
	{
		alert("Please enter Correct email address.");
		ClientForm.txtEmail.focus();
	}
	else
		ClientForm.submit();
}

function DoPrint()
{
	var sOption="toolbar=no,location=no,directories=no,menubar=no,"; 
	sOption+="scrollbars=yes,width=670,height=600,left=100,top=25"; 
	
	if(document.getElementById('HiddenBar'))
	{
		document.getElementById('HiddenBar').style.display =  'none';
	}
	var sWinHTML = document.getElementById('PrintDiv').innerHTML; 
	if(document.getElementById('HiddenBar'))
	{
		document.getElementById('HiddenBar').style.display =  '';
	}
	var winprint=window.open("","",sOption); 
	winprint.document.open(); 
	winprint.document.write('<html><LINK href="in_fls/style.css" rel="Stylesheet"><script src="in_fls/_functions.js" type="text/javascript"></script><body dir="ltr">'); 
	winprint.document.write(sWinHTML);          
	winprint.document.write('</body></html>'); 
	winprint.document.close(); 
	winprint.focus(); 
	winprint.print();
}

function DoSendFriend(Str)
{
	window.open("SendFriend.asp?Str="+escape(Str),"SendFriend","width=400, height=357");
}

function DoInviteFriend()
{
	window.open("InviteFriend.asp","InviteFriend","width=400, height=497");
}

function ShowHanuka()
{
	//window.open("HanukaPop.asp","HanukaPop","width=400, height=307");
}

function DoReminder(Str)
{
	window.open("ProductReminder.asp?Str="+escape(Str),"ProductReminder","width=400, height=177");
}

function DoWishList(Str)
{
	color = ShopFrm.SelectedColorID.value;
	size = ShopFrm.ItemSize.value;
	window.open("open_win_wishlist.asp?sID="+Str+"&size=" + size + "&color=" + color,"WishList","width=420, height=307");
}

function DoWishListUpdate(Str)
{
	color = ShopFrm.SelectedColorID.value;
	size = ShopFrm.ItemSize.value;
	wid = ShopFrm.wID.value;
	window.open("open_win_wishlist_update.asp?wID=" + wid + "&sID="+Str+"&size=" + size + "&color=" + color,"WishList","width=420, height=307");
}

function DoWishListAdmin(Str)
{
	window.open("open_win_wishlist_Adm.asp?lID="+Str,"WishList","width=420, height=237");
}

function AddComment(Str)
{
	window.open("Comment_Add.asp?Str="+Str,"AddComment","width=400, height=297");
}

function DoPaymentCard(Str)
{
	window.open("PaymentCard.asp","PaymentCard","width=400, height=257");
}

function openList(obj)
{
	if(obj.parentElement.parentElement.nextSibling)
	{
		if(obj.parentElement.parentElement.nextSibling.style.display=="")
		{
			obj.parentElement.parentElement.nextSibling.style.display="block";
			obj.src = "images/icon_arrow_index_on.gif";	
			
		}
		else
		{
			obj.parentElement.parentElement.nextSibling.style.display="";
			obj.src = "images/icon_arrow_index.gif";
		}
	}
}
							
function change_display(x,y) 
{
	var str="MyDiv1"
	var str1="MyDiv11" 
	var str2="MyDiv2" 
	var str22="MyDiv22" 
	
	if (document.all(str).style.display == "")
	{
		document.all(str).style.display = "none";
		document.all(str1).style.display = "none";
		document.all(str2).style.display = "";
		document.all(str22).style.display = "";
	}
	else
	{
		document.all(str).style.display = "";
		document.all(str1).style.display = "";
		document.all(str2).style.display = "none";
		document.all(str22).style.display = "none";
	}
}

function change_display1(z) 
{
	var str = "MyDiv" + z;
	var str2 = "tdopen" + z;
	
	if (document.all(str).style.display == "")
	{
		document.all(str).style.display = "none";
		document.all(str2).className = '';
		
	}
	else
	{
		document.all(str).style.display = "";
		document.all(str2).className = 'tdindex';
	}
}

function ShowHideDiv(Str)
{
	menuObj = eval('MenuDiv' + Str);
	iconObj = eval('MenuIcon' + Str);
	if(menuObj.style.display == 'none')
	{
		menuObj.style.display = '';
		iconObj.src = 'images/open_menu_0.gif'
	}
	else
	{
		menuObj.style.display = 'none';
		iconObj.src = 'images/arrow_menu_0.gif'
	}
}

function PopulateSubType(sStr, Lang) 
{
	var XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
	XMLDoc.async = false;
	//if(Lang =="En/")
	//	XMLDoc.load("XML//EnCategory" + eval("document."+sStr+".sType.value") + ".xml");
	//else if(Lang =="He/")
	XMLDoc.load("XML//Category" + eval("document."+sStr+".sType.value") + ".xml");
	while(eval("document."+sStr+".sSubType.options.length") > 1)
		eval("document."+sStr+".sSubType.removeChild(document."+sStr+".sSubType.options[1])");

	if(XMLDoc.hasChildNodes() == true)
	{
		var options = XMLDoc.childNodes[1].childNodes; 
		for(var i=1; i<options.length; i++) 
		{
			var objOption = document.createElement("OPTION");
			objOption.value = options[i].attributes[0].nodeValue;
			objOption.innerText = options[i].text;
			eval("document."+sStr+".sSubType.appendChild(objOption)");
		}
	}
}

function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 

function Set_Cookie(name,value,expires,path,domain,secure) { 
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
} 

function Delete_Cookie(name,path,domain) { 
   if (Get_Cookie(name)) document.cookie = name + "=" + 
      ( (path) ? ";path=" + path : "") + 
      ( (domain) ? ";domain=" + domain : "") + 
      ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
}

function open_close_menu(id)
{
	var id_img="img_"+id
	if (eval('document.getElementById("'+id+'").style.display==""'))
	{
		eval('document.getElementById("'+id+'").style.display="none"')
		eval('document.getElementById("'+id_img+'").src="images/xe_close.gif"')
	}
	else
	{
		eval('document.getElementById("'+id+'").style.display=""');  
		eval('document.getElementById("'+id_img+'").src="images/xe_down.gif"')
	}
}

function open_close_menu_green(id)
{
	var id_img="img_"+id
	if (eval('document.getElementById("'+id+'").style.display==""'))
	{
		eval('document.getElementById("'+id+'").style.display="none"')
		eval('document.getElementById("'+id_img+'").src="images/xe_green_close.gif"')
	}
	else
	{
		eval('document.getElementById("'+id+'").style.display=""');  
		eval('document.getElementById("'+id_img+'").src="images/xe_green.gif"')
	}
}

function popUp(url) 
{
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=515,height=440');
	self.name = "mainWin"; 
}

function PrintCoupon(Str)
{
	var sOption="toolbar=no,location=no,directories=no,menubar=no,"; 
	sOption+="scrollbars=yes,width=600,height=300,left=100,top=25"; 
	var sWinHTML = document.getElementById(Str).innerHTML; 
	var winprint=window.open("text/html","",sOption); 
	winprint.document.open(); 
	winprint.document.write('<html><LINK href="in_fls/style.css" rel="Stylesheet"><body dir="ltr">');
	//winprint.document.write('<html><LINK href="in_fls/style.css" rel="Stylesheet"><script src="in_fls/_functions.js" type="text/javascript"></script><body dir="ltr">'); 
	winprint.document.write(sWinHTML);          
	winprint.document.write('</body></html>'); 
	winprint.document.close(); 
	winprint.focus(); 
	winprint.print();
}

function PrintBenefit(Str)
{
	var sOption="toolbar=no,location=no,directories=no,menubar=no,"; 
	sOption+="scrollbars=yes,width=600,height=300,left=100,top=25"; 
	var sWinHTML = document.getElementById(Str).innerHTML; 
	var winprint=window.open("text/html","",sOption); 
	winprint.document.open(); 
	winprint.document.write('<html><LINK href="in_fls/style.css" rel="Stylesheet"><body dir="ltr">'); 
	//winprint.document.write('<html><LINK href="in_fls/style.css" rel="Stylesheet"><script src="in_fls/_functions.js" type="text/javascript"></script><body dir="ltr">');
	winprint.document.write(sWinHTML);          
	winprint.document.write('</body></html>'); 
	winprint.document.close(); 
	winprint.focus(); 
	winprint.print();
}

function ChangeBudget(Str)
{
	if(Str.value == 1)
	{
		frmGiftSearch.sPrice1.disabled = true;
		frmGiftSearch.sPrice.disabled = false;
	}
	else
	{
		frmGiftSearch.sPrice.disabled = true;
		frmGiftSearch.sPrice1.disabled = false;
	}
}

function ChangeBudget1(Str)
{
	if(Str.value == 1)
	{
		frmGiftSearch1.sPrice1.disabled = true;
		frmGiftSearch1.sPrice.disabled = false;
	}
	else
	{
		frmGiftSearch1.sPrice.disabled = true;
		frmGiftSearch1.sPrice1.disabled = false;
	}
}

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}