function hideByID(elementName) {
	document.getElementById(elementName).style.display='none';
}

function showByID(elementName) {
	document.getElementById(elementName).style.display='inline';
}

function showHideByID(elementName) {
	if (document.getElementById(elementName).style.display=='inline') {
		hideByID(elementName)
	} else {
		showByID(elementName)
	}
}

function changeText(elementName,theText) {
	return document.getElementById(elementName).innerHTML=theText;
}


function changeFormAction(formName,actionPage) {
	return document.getElementById(formName).action=actionPage;
}

function getText(elementName) {
	return document.getElementById(elementName).innerHTML;
}


function changePic(elementName,thePic) {
	document.getElementById(elementName).src=thePic;
}

function makeReadOnly(elementName,theState) {
	document.getElementById(elementName).readOnly=theState;
}

function submitForm(elementName) {
	document.getElementById(elementName).submit();
}

function clearInput(elementName) {
	document.getElementById(elementName).value='';
}

function getFieldValue(elementName) {
	if (document.getElementById(elementName)) {return document.getElementById(elementName).value;}
}

function changeFieldValue(srcField,newValue) {
	if (document.getElementById(srcField)) {
		document.getElementById(srcField).value=newValue
	}
}

function changeClass(elementName,theClassName) {
	document.getElementById(elementName).className=theClassName;
}

function changeBackroundImage(elementName,imageName) {
	document.getElementById(elementName).style.backgroundImage="url('"+imageName+"')";
}

function changeBackroundColor(elementName,color) {
	document.getElementById(elementName).style.backgroundColor=color;
}


function enableBtn(btnName) {
	document.getElementById(btnName).disabled=false;	
}

function disableBtn(btnName) {
	document.getElementById(btnName).disabled=true;	
}

function deleteItem(deleteTitle,pageName,refreshElem,idField,itemID,theTable,moreParams) {
	var agree=confirm ('האם אתה בטוח שברצונך למחוק את '+deleteTitle+' ?');
	if (agree) {
		pageName = pageName+'?mode=doDelete&adminID=<?=$_REQUEST[adminID];?>&idField='+idField+'&idFieldValue='+itemID+'&theTable='+theTable+'&'+moreParams;
		reloadPage(pageName,'',refreshElem);
	} 
}


var xmlHttp;
function reloadPage(pageName,formName,refreshElem) {
	xmlHttp=GetXmlHttpObject(); 
	xmlHttp.onreadystatechange=stateChanged;
	function stateChanged() {
	if (xmlHttp.readyState==4) {
		document.getElementById(refreshElem).innerHTML=xmlHttp.responseText;}	
	}
	var url='';
	if (formName) {
		var x=document.getElementById(formName);
		for (var i=0;i<x.length;i++) {
			url += x.elements[i].name+'='+x.elements[i].value+'&';
		}
	}
	xmlHttp.open("POST",pageName,true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8'); 
	xmlHttp.send(url)
}

function reloadPageEval(pageName,formName,refreshElem) {
	xmlHttp=GetXmlHttpObject(); 
	xmlHttp.onreadystatechange=stateChanged;
	function stateChanged() {
	if (xmlHttp.readyState==4) {
		eval(document.getElementById(refreshElem).innerHTML=xmlHttp.responseText);}	
	}
	var url='';
	if (formName) {
		var x=document.getElementById(formName);
		for (var i=0;i<x.length;i++) {
			url += x.elements[i].name+'='+x.elements[i].value+'&';
		}
	}
	xmlHttp.open("POST",pageName,true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8'); 
	xmlHttp.send(url)
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		xmlHttp=new XMLHttpRequest();
  	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


function checkEmail(emailField,infoFld) {
	var str = document.getElementById(emailField).value;
	var at="@"
	var dot="."
	var off=""
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1) {off=1;}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)  {off=1;}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)  {off=1;}
	if (str.indexOf(at,(lat+1))!=-1)  {off=1;}
	if (str.indexOf(" ")!=-1) {off=1;}
	if (off==1) {
		changeText(infoFld,'This is not valid e-mail address');
		return false;
	}  else {
		changeClass(infoFld,'okayField');
		changeText(infoFld,'E-Mail address valid');
		return true;
	}
}

function checkEmailNoInfo(emailField) {
	var str = document.getElementById(emailField).value;
	var at="@"
	var dot="."
	var off=""
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1) {off=1;}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)  {off=1;}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)  {off=1;}
	if (str.indexOf(at,(lat+1))!=-1)  {off=1;}
	if (str.indexOf(" ")!=-1) {off=1;}
	if (off==1) {
		return 0;
	}  else {
		return 1;
	}
}



function checkInputData(elementName,elementCaption,msgField,minimumChars,errorClass,okayClass) {
	if (minimumChars == 0) {
		if (!document.getElementById(elementName).value) {
			changeClass(msgField,'errorField');
			changeText (msgField,elementCaption+" can't be empty");
			return false;
		} else {
			changeClass(msgField,'okayField');
			changeText (msgField,'');
			return true;
		}
	} else {
		if (document.getElementById(elementName).value.length < minimumChars) {
			changeClass(msgField,'errorField');
			changeText (msgField,'the '+elementCaption+' must contain at least '+ minimumChars+' characters');
			return false;
		} else {
			changeClass(msgField,'okayField');
			changeText (msgField,'');
			return true;
		}
	}	
}

function checkInputDataWithFocus(elementName,elementCaption,msgField,minimumChars,errorClass,okayClass,nextField) {
	var tabi = document.getElementById(elementName).tabIndex;
	nextTab = tabi+1;
	if (minimumChars == 0) {
		if (!document.getElementById(elementName).value) {
			changeClass(msgField,'errorField');
			changeText (msgField,elementCaption+" can't be empty");
			return false;
		} else {
			changeClass(msgField,'okayField');
			document.getElementById(nextField).focus();
			changeText (msgField,'');
			return true;
		}
	} else {
		if (document.getElementById(elementName).value.length < minimumChars) {
			changeClass(msgField,'errorField');
			changeText (msgField,'the '+elementCaption+' must contain at least '+ minimumChars+' characters');
			return false;
		} else {
			changeClass(msgField,'okayField');
			changeText (msgField,'');
			document.getElementById(nextField).focus();
			return true;
		}
	}	
}

function checkPasses(passField,passVerField,dontMatchCaption,minimumChars,errBG,okayBG) {
	if ((document.getElementById(passField).value != document.getElementById(passVerField).value)) {
		changeClass('passFail','errorField');
		changeText ('passFail','passwords do not match');
		return false;
	} else {
		changeClass('passFail','okayField');
		changeText ('passFail','passwords okay');
	}

	if ((document.getElementById(passField).value.length < 4)) {
		changeClass('passFail','errorField');
		changeText ('passFail','the password field must conatin at least 4 characters');
		return false;
	} else {
		changeClass('passFail','okayField');
		changeText ('passFail','passwords okay');
	}
}



var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e){
if (ie5&&dragapproved&&event.button==1){
document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
}
}

function initializedrag(e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getElementById("dwindowcontent").style.display="none" //extra
tempx=parseInt(document.getElementById("dwindow").style.left)
tempy=parseInt(document.getElementById("dwindow").style.top)

dragapproved=true
document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height){
if (!ie5&&!ns6)
window.open(url,"","width=width,height=height,scrollbars=1")
else{
document.getElementById("dwindow").style.display=''
document.getElementById("dwindow").style.width=initialwidth=width+"px"
document.getElementById("dwindow").style.height=initialheight=height+"px"
document.getElementById("dwindow").style.left="30px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
document.getElementById("cframe").src=url
}
}

function maximize(){
if (minrestore==0){
minrestore=1 //maximize window
document.getElementById("maxname").setAttribute("src","restore.gif")
document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
}
else{
minrestore=0 //restore window
document.getElementById("maxname").setAttribute("src","max.gif")
document.getElementById("dwindow").style.width=initialwidth
document.getElementById("dwindow").style.height=initialheight
}
document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit(){
document.getElementById("dwindow").style.display="none"
}

function stopdrag(){
dragapproved=false;
document.getElementById("dwindow").onmousemove=null;
document.getElementById("dwindowcontent").style.display="" //extra
}


function checkRadioChecked(elemntName) {
	var colRadio = document.getElementsByName(elemntName);
	for (var i=0;i<colRadio.length;i++) {
		if (colRadio[i].checked) {
			return (colRadio[i].value);
		} 
	}
	return false;
}

function goToPrev() {
	var prevValue=getFieldValue('curstep');
	var goTo = prevValue-1;
	hideByID('step'+prevValue);
	showByID('step'+goTo);
	changeFieldValue('curstep',goTo);
	if (goTo == 1) {
		hideByID('btnPrev');
		showByID('btnNext');
	}
	if (prevValue != 1) checkStep(prevValue);
}

function goToNext() {
	var nextValue=getFieldValue('curstep');
	nextValue++;
	var prevValue = nextValue-1;
	changeFieldValue('curstep',nextValue);
	hideByID('step'+prevValue);
	showByID('step'+nextValue);
	if (nextValue == 14) {
		showByID('btnPrev');
		hideByID('btnNext');
	} else {
		showByID('btnPrev');
	}
	checkStep(nextValue);
} 

function entitySelected(obj){
	myCount = 0;
	for (i=0;i<obj.length;i++){
		if (obj[i].checked){
			myCount++;
		}
	}
	return myCount;
}

function anyCheck(contrlName,minInput,maxInput) {
	var checks = document.getElementsByName(contrlName);
	if ((entitySelected(checks)>maxInput) || (entitySelected(checks)<minInput)) {
		hideByID('btnNext');
	} else {
		showByID('btnNext');
	}
}

function anyCheckEditMulti(contrlName,minInput,maxInput) {
	var checks = document.getElementsByName(contrlName);
	if ((entitySelected(checks)>maxInput) || (entitySelected(checks)<minInput)) {
		return 0;
	} else {
		return 1;
	}
}

function textCounter(field,btnName,counter,maxlimit) {	
	var fieldWidth = parseInt(field.offsetWidth);
	var charcnt = field.value.length;
	if (charcnt > maxlimit) { 
		return 1;
	} else { 
		var percentage = parseInt(100 - ((maxlimit - charcnt) * 100)/maxlimit) ;
		document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
		document.getElementById(counter).innerHTML=" "+percentage+"%"
		setcolor(document.getElementById(counter),percentage,"background-color");
		return false;
	}
}
function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

function checkTerms(elementName) {
	if (document.getElementById(elementName).checked == true) {
		changeText ('agreeFail',"");	
		return 1;
	} else {
		changeClass('agreeFail','errorField');
		changeText ('agreeFail',"You have to agree the terms of conditions");	
		return 0;
	}	
}

function textCount(elementName,numChars) {
	if(document.getElementById(elementName).value.length >= numChars) {
		return 1;
	} else {
		return 0;
}	
}


function foldMenu(elementName) {
		if (document.getElementById(elementName).style.display=='inline') {
			hideByID(elementName);
		} else {
			showByID(elementName);
		}
}


function handleFavs(customerID,favID) {
	reloadPageEval('profileChangeFav.php?customerID='+customerID+'&favID='+favID,'','silentAction');
	if (getFieldValue('favStatus') == 0) {
		changeFieldValue('favStatus','1');
		changeText('addToFav','הסרה מהמועדפים');
		changePic('favIcon','images/removefavoriteIcon.gif');
	} else {
		changeFieldValue('favStatus','0');
		changeText('addToFav','הוספה למועדפים');
		changePic('favIcon','images/adfavoriteIcon.gif');
	}
}

function handleBlackList(customerID,blackListedID) {
	reloadPageEval('profileChangeBlackList.php?customerID='+customerID+'&blackListedID='+blackListedID,'','silentAction');
	if (getFieldValue('blackListStatus') == 0) {
		changeFieldValue('blackListStatus','1');
		changeText('addToBlack','הסרה מהרשימה השחורה');
		changePic('blackListIcon','images/removeFromblacklistIcon.gif');
	} else {
		changeFieldValue('blackListStatus','0');
		changeText('addToBlack','הוספה לרשימה השחורה');
		changePic('blackListIcon','images/addblacklistIcon.gif');
	}
}

function changePicStatus(picID,privatePic) {
	reloadPageEval('myPicsChangeStatus.php?picID='+picID+'&privatePic='+privatePic,'','silentAction');
	if (getFieldValue('privatePic'+picID) == "off") {
		changeFieldValue('privatePic'+picID,'on');
		changeText('picStatus'+picID,'<font color=red>תמונה פרטית</font>');
	} else {
		changeFieldValue('privatePic'+picID,'off');
		changeText('picStatus'+picID,'<font color=green>תמונה ציבורית</font>');
	}
}

function changePicStatus(picID,privatePic) {
	reloadPageEval('myPicsChangeStatus.php?picID='+picID+'&privatePic='+privatePic,'','silentAction');
	if (getFieldValue('privatePic'+picID) == "off") {
		changeFieldValue('privatePic'+picID,'on');
		changeText('picStatus'+picID,'<font color=red>תמונה פרטית</font>');
	} else {
		changeFieldValue('privatePic'+picID,'off');
		changeText('picStatus'+picID,'<font color=green>תמונה ציבורית</font>');
	}
}



function changePicMain(picID,isMain) {
	reloadPageEval('myPicsChangeStatus.php?setMain=1&picID='+picID+'&isMain='+isMain,'','silentAction');
	if (getFieldValue('mainPic'+picID) == "off") {
		changeFieldValue('mainPic'+picID,'on');
		changeText('picMain'+picID,'<font color=green>תמונה ראשית</font>');
	} else {
		changeFieldValue('mainPic'+picID,'off');
		changeText('picMain'+picID,'<font color=gray>תמונה ראשית</font>');
	}
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else  var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function openWin(target,winName,width,height,scrollbars,toolbars) {
	window.open(target,winName,'toolbars='+toolbars+',width='+width+',height='+height+',scrollbars='+scrollbars);
}

function dimm(){
 		if ($('dimmer')){
		document.body.removeChild($('dimmer'));
		return false;
	}
	//var width = document.body.offsetWidth + "px";
	var height = document.body.offsetHeight +"px";
	var el = document.createElement('div');
	el.appendChild(document.createTextNode(' '));
	el.className = 'dimmer';
	el.id = 'dimmer';
	//el.style.width = width;
	el.style.height = height;
	document.body.appendChild(el);
}

function minisite(pageName){
	dimm();
	if ($('minisiteBox')){
		document.body.removeChild($('minisiteBox'));
		return false;
	}
	iframe = document.createElement('iframe');
	div = document.createElement('div');
	div.id = 'minisiteBox';
	//iframe.src = 'minisite/minisite.htm';
	iframe.src = pageName;
	div.appendChild(iframe);
	document.body.appendChild(div);
	
}

function showMinisite(pageName){
	var pageName1=pageName;
	minisite(pageName1);			
}


function setMiniCookie(value){	
	showmini = (value)?value:((document.forms[0].mini.value="")?"off":"on");
	setCookie( 'showmini', showmini, 365, "/", "shopfromisrael.com", false );
}
function getMiniCookie(){
	return getCookie('showmini')
}

function closeMinisite() {
	if (parent) {parent.minisite();return false}
}


function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
// like php $_GET
function $_get(name){
	querystring = window.location.search;
	if (!querystring) return "";
	start = querystring.indexOf(name+"=");
	if (start<0) return "";
	end = querystring.indexOf("&",start);
	if (end<0) end = querystring.length;
	value = querystring.substr(start + name.length + 1,end);
	return value;
}


var disappeardelay=3000  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=0 //hide menu when user clicks within menu? (1=yes, 0=no)

/////No further editting needed

var ie5=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(obj, e, visible, hidden){
	if (ie5||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top=-500
	if (e.type=="click" && obj.visibility==hidden || e.type=="click")
		obj.visibility=visible
	else if (e.type=="click")
		obj.visibility=hidden
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=35
	if (whichedge=="rightedge"){
		var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	} else {
		var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
		edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
		if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
			edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
}

function dropdownmenu(obj, e, dropmenuID){
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	if (typeof dropmenuobj!="undefined") //hide previous menu
	dropmenuobj.style.visibility="hidden"
	clearhidemenu()
	if (ie5||ns6){
		obj.onmouseout=delayhidemenu
		dropmenuobj=document.getElementById(dropmenuID)
		if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
		dropmenuobj.onmouseover=clearhidemenu
		dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
		showhide(dropmenuobj.style, e, "visible", "hidden")
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	}
	return clickreturnvalue()
}


function dropdownmenuAllCats(obj, e, dropmenuID){
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	//if (typeof dropmenuobj!="undefined") //hide previous menu
	//dropmenuobj.style.visibility="hidden"
	clearhidemenu()
	if (ie5||ns6){
		obj.onmouseout=delayhidemenu
		dropmenuobj=document.getElementById(dropmenuID)
		if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
		dropmenuobj.onmouseover=clearhidemenu
		dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
		showhide(dropmenuobj.style, e, "visible", "hidden");
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	}
	return clickreturnvalue()
}

function clickreturnvalue(){
	if ((ie5||ns6) && !enableanchorlink) return false
	else return true
}

function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function dynamichide(e){
	if (ie5&&!dropmenuobj.contains(e.toElement)) {
		delayhidemenu()
		
	} else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu()
}

function delayhidemenu(){
	delayhide=setTimeout("dropmenuobj.style.visibility='hidden';showByID('srchBar');",disappeardelay);
	
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
	clearTimeout(delayhide)
}


function openGiftWindow(product) {
	var selectedGift = getFieldValue('gift');
	if ((!selectedGift) || (selectedGift=='Select Free Gift')) {
		alert ('This product have a gift\nTo see it, Please choose one');
	} else {
		showMinisite('productGift.php?giftPic='+selectedGift);	
	}
}



function checkAdditionalMoney(elemntName,calcElemnt) {
	var hidVal  = new Array();
	eval(getText('hidVal1'));
	var elem = document.getElementById('addToCartForm').elements;
	var elemName = "";
	var elemExplode= "";
	var subExtras = 0;
	for(var i=0;i<elem.length;i++){
		elemName = elem[i].name;
		elemExplode = elemName.indexOf("custom");
		if (elemExplode > -1) {
			if (hidVal[elem[i].value]) {	
				subExtras = (subExtras*1)+(hidVal[elem[i].value]*1);
			}
		}
	}
	subExtras = subExtras.toFixed(2);
	changeText('extras',subExtras);
	var ourPrice = getFieldValue('ourPriceHid');
	var newSubtotal = 0;
	newSubtotal = (ourPrice*1)+(subExtras*1);
	newSubtotal = newSubtotal.toFixed(2);
	changeText('subTotal1',newSubtotal);
}


function changeMainPic(id,productID) {
	reloadPageEval('productCheckSpecialPic.php?id='+id+'&productID='+productID,'','extrasDiv');	
}





var delayb4scroll=1000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit=1 //Pause marquee onMousever (0=no. 1=yes)?
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''

function scrollmarquee(){
	if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8)) 
		cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
	else
		cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}

function initializemarquee(){
	cross_marquee=document.getElementById("vmarquee")
	cross_marquee.style.top=0
	marqueeheight=document.getElementById("marqueecontainer").offsetHeight
	actualheight=cross_marquee.offsetHeight
	if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
	cross_marquee.style.height=marqueeheight+"px"
	cross_marquee.style.overflow="scroll"
	return
	}
	setTimeout('lefttime=setInterval("scrollmarquee()",40)', delayb4scroll)
}

function runnews() {
	if (window.addEventListener) 
		window.addEventListener("load", initializemarquee, false)
	else if (window.attachEvent)
		window.attachEvent("onload", initializemarquee)
	else if (document.getElementById)
		window.onload=initializemarquee
}

function updateQuantity(boxID) {
	location.href='basket.php?mode=doUpdate&shopCartID='+boxID+'&quanValue='+getFieldValue('quan'+boxID);
}

function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


function wholeSaleUpdateCalc(ourPrice,quantity,totalPriceField,subCat,parent,shopCartID) {
	if (quantity > 0) {
	var newValue = ourPrice*quantity;
	newValue = newValue.toFixed(2);
	changeText(totalPriceField,newValue);
	location.href='basket.php?mode=doUpdate&subCat='+subCat+'&parent='+parent+'&shopCartID='+shopCartID+'&quanValue='+quantity;
	} else {
		alert ('product quantity must be more then 0');	
	}
}

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		return false;
	} 
}      

function checkPrices() {
	var subTot = getText('subTotal1');
	if (parseInt(subTot) > 0) {
		reloadPageEval('addToCartDoAjax.php','addToCartForm','submitCart');
	} else {
		alert ('You have to choose one or more from  the product options');
	}
}