

function onloadPicFnct(pc)
{
	try {
		if (pc.width < pc.height) {
			if (pc.height<130) {
				pc.height = '100';
			} 
			else {
				pc.height = '130';
			}
		} 
		else {
			if (pc.width<130) {
				pc.width = '100';
			} 
			else {
				pc.width = '130';
			}
		}
	}
	catch (e) {alert (e);}
}



function onloadPic1(pic)
{
	try {
		var pc = document.getElementById (pic);
		
		if ((pc.width)<=(pc.height)){
			pc.height = '130';
			} 
		else{
			pc.width = '130'; 
		}
	}
	catch (e) {alert (e);}
}


function onloadPic2()
{
	var pc = document.getElementById ("bigpic");
	
	if ((pc.width)<=(pc.height)){
		if (pc.height<500) {
			if (pc.height<400) {
				pc.height = pc.height*1.25;
				this.window.height = pc.height + 30;
				this.window.width = pc.width*1.25 + 30;
			} 
			else {
				pc.height = '400';
			}  
			} 
		else {pc.height = '500';} 
		} 
	else{
		if (pc.width<500) {
			if (pc.width<400) {pc.width = pc.width*1.25;} 
			else {pc.width = '400';}} 
		else {pc.width = '500';} 
	}
}


function Search_onchange() {
Search.submit()
}

function ImageResize(img, size) {
	if ((img.width)<=(img.height)){
		if ((img.height < size)) {
			img.height = img.height;
		}
		else {
			img.height = size;
		}
	}
	else {
		if ((img.width < size)){
			img.width = img.width;
		}
		else {
			img.width = size;
		}
	}
}



function
UpdateBasket(
){
//	var nodeBasket = document.getElementById ("ifmBasket");
//	nodeBasket.src = "../html/dialogs/blank.htm";
//	nodeBasket.src = "basketbox.asp";
//	window.frames[1].reload();

//	window.setTimeout (
//		"window.frames[1].Refresh ();",
//		1000
//	);

//	window.location = "index.asp?IsRefreshBasket=1";
}




function
OnLoad (
){
	ChangeLanguage (
		g_strSysLanguage,
		false
	);	
}


function
Redirection (
	strURL
){
	var nodeCenter = document.getElementById ("ifCenter");
	nodeCenter.src = "../html/dialogs/blank.htm";
	nodeCenter.src = strURL+"?LNG="+g_strSysLanguage;
}

function
NewRedir (
	strURL
){
	var nodeCenter = document.getElementById ("ifCenter");
	nodeCenter.src = strURL+"&LNG="+g_strSysLanguage;
}


function
ChangeLanguage (
	strType,
	fIsRefresh
){
	var nodeEng = document.getElementById ("btnEng");
	var nodeHeb = document.getElementById ("btnHeb");
	var nodeFre = document.getElementById ("btnFre");

	if (strType == "ENG") {
		nodeEng.src = "../html/images/englishiconmo.gif";
		nodeHeb.src = "../html/images/hebrewicon.gif";
		nodeFre.src = "../html/images/frenchicon.gif";

		g_strSysLanguage = "ENG";
	}
	else if (strType == "HEB") {
		nodeEng.src = "../html/images/englishicon.gif";
		nodeHeb.src = "../html/images/hebrewiconmo.gif";
		nodeFre.src = "../html/images/frenchicon.gif";

		g_strSysLanguage = "HEB";
	}
	else if (strType == "FRE") {
		nodeEng.src = "../html/images/englishicon.gif";
		nodeHeb.src = "../html/images/hebrewicon.gif";
		nodeFre.src = "../html/images/frenchiconmo.gif";

		g_strSysLanguage = "FRE";
	}
	
	if (fIsRefresh) {
		window.location = "index.asp?LNG="+g_strSysLanguage;
	}
}


function
OnSearch (
){
	var strItemName = document.getElementById ("txtName").value;
	var strCode = document.getElementById ("txtCode").value;
	var strCatagory = document.getElementById ("slctCatagory").value;

	var strURL = (
		"searchresult.asp?"+
		"LNG="+g_strSysLanguage+
		"&SearchTable=tblItems"+
		"&ItemName="+strItemName+
		"&Code="+strCode+
		"&Catagory="+strCatagory
	);

	var nodeCenter = document.getElementById ("ifCenter");
	nodeCenter.src = "../html/dialogs/blank.htm";
	nodeCenter.src = strURL;
}


function
CloseMenus (
){
	if (g_nLastMenu != null) {
		var nodeSubMenu = document.getElementById ('tblMenu'+g_nLastMenu);
		nodeSubMenu.style.display = 'none';		
	}
}


function
OnClickCatagory (
	nIndex	
){
	if (g_fIsCatagory) {
		var strURL = (
			"itemslist.asp?"+
			"LNG="+g_strSysLanguage+
			"&ObjectId="+nIndex+
			"&SearchTable=tblItems"+
			"&SearchFields=nCatagoryId"
		);

		var nodeCenter = document.getElementById ("ifCenter");
		nodeCenter.src = "../html/dialogs/blank.htm";
		nodeCenter.src = strURL;
	}

	g_fIsCatagory = true;	
}


function
OnClickSubMenu (
	nCatagoryId,
	nSubCatagoryId
){
	g_fIsCatagory = false;

	var strURL = (
		"itemslist.asp?"+
		"LNG="+g_strSysLanguage+
		"&ObjectId="+nCatagoryId+"_"+nSubCatagoryId+
		"&SearchTable=tblItems"+
		"&SearchFields=nCatagoryId_nSubCatagoryId"
	);

	var nodeCenter = document.getElementById ("ifCenter");
	nodeCenter.src = "../html/dialogs/blank.htm";
	nodeCenter.src = strURL;
}

function GoToBasket()
{
	var nodeCenter = document.getElementById ("ifCenter");
	nodeCenter.src = "../html/dialogs/blank.htm";
	nodeCenter.src = "Basket.asp?TableName=tblItems&LNG=<%=strLanguage%>";
}

function
OnOverMenu (
	nIndex
){
	try {
		CloseMenus ();
		
		var nodeSubMenu = document.getElementById ('tblMenu'+nIndex);
		nodeSubMenu.style.display = '';

		g_nLastMenu = nIndex;
	}
	catch (e) {}
}


function
SetIFrameSize (
	nHeight
){
	var nodeCenter = document.getElementById ("ifCenter");
	nodeCenter.height = nHeight;
}

function
OnKeyDown (
	evtEvent
){
	if (evtEvent.keyCode == 13) {
		OnSearch ();
	}
}

function
SetNewPage (
	strURL
){
	var nodeIfCenter = document.getElementById ("ifCenter");
	nodeIfCenter.src = "../html/dialogs/blank.htm";

	nodeIfCenter.src = strURL;
}



	function openwin(winname,width,height,scroll)
	{
		window.open(winname,"window","width="+width+",height="+height+",top=150,left=150,toolbars=no,scrollbars="+scroll);
	}  
	
	
	
	

function FormToXml(F)
{
	str = ""
	for (i=0 ; i<F.length ; i++)
	{
		str += "<" + F.elements [i].name + ">\n"
		+ F.elements [i].value + "\n" 
		+ "</" + F.elements [i].name + ">\n"
	}
	return str
}

function calculate(f)
{
//now we dont need ClothPrice : Price = width*height*price_for_metr
	try{
		f.Price.value = ""
		
		
		
		var width = parseFloat(f.width.value);
		var height = parseFloat (f.height.value);
		var area =  width * height 
		var price 

		
		var span_price = document.getElementById( "span_price_" + f.ItemId.value )
		var div_add = document.getElementById( "div_add_" + f.ItemId.value )

		if(isNaN(area) ){
			span_price.innerText = 0
			div_add.style.visibility = 'hidden'
			return
		}
		
//here we know exectly that width and height is entered correctly

		if(	width >=f.SmallFSize .value 
			&& width <= f.SmallTSize.value  
		){
			price = area *  f.SmallPrice.value
		}
		else if(	width>=f.MediumFSize.value 
					&& width<= f.MediumTSize.value  
		){
			price = area * f.MediumPrice.value
		}
		else if(	width>=f.BigFSize.value 
					&& width<= f.BigTSize.value  
		){
			price = area * f.BigPrice.value
		}
		else{
			price= area *  f.BigPrice.value
		}

		price = Math.round(price)

		span_price.innerText = price
		f.Price.value = price
		div_add.style.visibility = 'visible'

	}
	catch(e){
		//alert(e.description)
	}
}




function calculateInches(f)
{

	try{
		f.Price.value = ""
		
		
		// Reseiving the data in inches !!!!
		var width = parseFloat(f.widthInches.value);
		var height = parseFloat (f.heightInches.value);
		// Converting from inches to meters:
		width = width * 0.0254;
		height = height * 0.0254;
		
		var area =  width * height 
		var price 

		
		var span_price = document.getElementById( "span_price_" + f.ItemId.value )
		var div_add = document.getElementById( "div_add_" + f.ItemId.value )

		if(isNaN(area) ){
			span_price.innerText = 0
			div_add.style.visibility = 'hidden'
			return
		}
		
//here we know exectly that width and height is entered correctly

		if(	width >=f.SmallFSize .value 
			&& width <= f.SmallTSize.value  
		){
			price = area *  f.SmallPrice.value
		}
		else if(	width>=f.MediumFSize.value 
					&& width<= f.MediumTSize.value  
		){
			price = area * f.MediumPrice.value
		}
		else if(	width>=f.BigFSize.value 
					&& width<= f.BigTSize.value  
		){
			price = area * f.BigPrice.value
		}
		else{
			price= area *  f.BigPrice.value
		}

		price = Math.round(price)

		span_price.innerText = price
		f.Price.value = price
		div_add.style.visibility = 'visible'

	}
	catch(e){
		//alert(e.description)
	}
}



function
AddToBasketByXml (
	form
){
//	alert(FormToXml(form) )
//	return
	try {
		g_ecmManager.AddToBasketByFormXml (
			FormToXml(form) ,
			g_ecmManager.typeUpdateCount
		);
		document.location = "basket.asp?IsRefreshBasket=1&LNG=<%=strLanguage%>";
	}
	catch (e) {
		
		alert (
			e.message + "\n"  +
			e.description				
		);
	}
}


