﻿
function SetInnerHTML (elementName, htmlData){
	if ($(elementName))
		$(elementName).innerHTML = htmlData;
}
function ShowMessage (engineMessage, flagRefresh){
	alert (engineMessage);
	if (flagRefresh) RefreshAuctionData();
}
// Run eval command for a group of elements.
function RunOnElements (element, propertyName, propertyValue, cmd) {
	var a = document.getElementsByTagName(element), i = a.length;
	while( i-- ) { var tmp = cmd;
		while (tmp.indexOf("{e}") != -1) tmp = tmp.replace("{e}", "a[" + i + "]");
		if(eval("a[i]." + propertyName) == propertyValue ) eval(tmp);
}}

// Run eval command for every element on page that corespond to the prefix condition
function RunOnAllElements (element, propertyName, prefix, cmd) {
	try {
		var a = document.getElementsByTagName(element), i = a.length, tmp = "";
		while( i-- ) {
			tmp = cmd;
			while (tmp.indexOf("{e}") != -1) tmp = tmp.replace("{e}", "a[" + i + "]");
			var propertyValue = eval("a[i]." + propertyName);
			if(propertyValue && propertyValue.indexOf(prefix)==0 ) eval(tmp);
		}
	} catch (e) { return true; } return false;
}

function IsOnlyWord(value){
	if(value.length == 0) return true;
	var ch;
	var allowChars = "'-/."
	
	for(var i=0; i<value.length; i++)
	{
		ch=value.charAt(i)
		if(!((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") || 
			 (ch >= "0" && ch <= "9") || (ch >= "א" && ch <= "ת")  || 
			 (ch == " ") || (ch == '"') || (allowChars.indexOf(ch, 0) != -1))) 
		{
				return false;

		}
	}
	return true;
}
function Trim(value, removeChar){
	value = RTrim(value, removeChar)
	value = LTrim(value, removeChar)
	return value
}

function LTrim(value, removeChar){
	var fr=-1, i
	var ret = new String()
	var charToRemove = " ";
	ret = value;
	
	if (removeChar != null) 
	{
		if (removeChar.length > 1)
			charToRemove = removeChar.substring(0, 1)
		else 
			charToRemove = removeChar;
	}
	
	for(i=0; i < ret.length; i++)
	{
		if(ret.charAt(i) != charToRemove) 
		{
			fr = i;
			break;
		}
	}
	if(fr == -1) return "";
	if(fr == 0) return value;
	return ret.substring(fr, ret.length);
}

function RTrim(value, removeChar){
	var to=-1, i
	var ret = new String()
	var charToRemove = " ";
	ret = value;
	
	if (removeChar != null) 
	{
		if (removeChar.length > 1)
			charToRemove = removeChar.substring(0, 1)
		else 
			charToRemove = removeChar;
	}
	
	for(i=ret.length-1; i >= 0; i--)
	{
		if(ret.charAt(i) != charToRemove) 
		{
			to = i;
			break;
		}
	}
	if(to == -1) return "";
	if(to == ret.length-1) return value;
	return ret.substring(0, to+1);
}

//check valid price
function IsPrice(value)
{
	if (value.length > 0)
	{
		var i
		
		for(i=value.length-1; i >= 0; i--)
		{
			if(value.charAt(i) < "0" || value.charAt(i) > "9") 
			{
				if(value.charAt(i) != "." || value.charAt(i) != ",")
					return false;
			}
		}
	}
	return true;
}

function IsPhoneValid(phone)
{
	if(phone.length == 0 ) return false;
	if(phone.substring(0,1) == "0") return false;
	
	var pattern = /^\d{7}$/
	return (pattern.test(phone) && eval(phone) > 0)
}

function IsEmailValid(email)
{
	if(email.length == 0) return true
	var pattern =  /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/
	return pattern.test(email)
}

function IsIdNumberValid(id)
{
	if(id.length == 0 || id.length != 9) return false;
	
	var testID = Trim(id)
	var sum = 0
	var tmp = 0
	var mult = 0
	var i = 0

	if(testID == "" || testID.length==0)
	{
		return false;
	}
	if(testID.length > 9 || testID.length < 8)
	{
		return false;
	}
	if(testID.length % 2 == 0)
	{
		mult = 2
	}
	else 
	{	
		mult = 1
	}

	for(i = 0; i < testID.length - 1; i++)
	{
		try
		{
			tmp = testID.charAt(i) * mult
			if(tmp > 9)
			{
				tmp = 1 + tmp - 10
			}
			sum += tmp
			if(mult == 2)
			{
				mult = 1
			}
			else
			{
				mult = 2
			}
		}
		catch(err)
		{
			return false;
		}		
	}

	sum += testID.charAt(testID.length - 1) * 1
	if(sum > 0 && sum % 10 == 0)
	{
		return true;
	}
	else 
	{
		return false;
	}
}
function ResizeCloseLabel(divName)
{
	var ctrl;
	try 
	{ 
		ctrl = $(divName);
		
		ctrl.style.left   = FindPosX(ctrl);
		ctrl.style.top    = FindPosY(ctrl);		
		ctrl.className	="LockAuctionBox";
			
	} catch(ex){}

	function FindPosX(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
		curleft += obj.x;
		return curleft;
	}

	function FindPosY(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
		curtop += obj.y;
		return curtop;
	}
}


function ResizeSaleCloseLabel(divName)
{
	if (divName == null) divName = 'MainSale';
	var ctrl, img;
	try 
	{ 
		ctrl = $(divName);
		img	 = $("imgCloseAuction");
		if (ctrl && img){
			img.style.left   = FindPosX(ctrl) + 'px' ;
			img.style.top    = FindPosY(ctrl) + 'px' ;
			img.style.width  = ctrl.offsetWidth + 'px';
			img.style.height = ctrl.offsetHeight + 'px';
		}
	} catch(ex){}

	function FindPosX(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
		curleft += obj.x;
		return curleft;
	}

	function FindPosY(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
		curtop += obj.y;
		return curtop;
	}
}

function BrandFind(theBrand)
{
	if(event.offsetX < 0 || event.offsetX >36 || event.offsetY < 0 || event.offsetY >19) return false;
	
	objBrand = $(theBrand);
	
	msgText = ""
	if (objBrand.selectedIndex == 0)
	{
		objBrand.className="InvalidFormField"
		msgText += $("BRAND_NO_CHOICE").value + "\n"
	}
	else 
	{
		objBrand.className="FormField"
	}
	
	if (msgText != "")
	{
		alert(msgText);
		return false;
	}
    return true;
}
function CheckSimpleInputValidateOnEnter(theText, ev)
{	
	var characterCode = 0;
	var sender;
	if (ev.which != null) {
		characterCode = ev.which;
		sender = ev.target;
	}
	else {
		characterCode = ev.keyCode;
		sender = ev.srcElement;
	}
    
    if(characterCode == 13) 
    {
		if (SimpleInputValidate(theText, true))
		{
			$("SiteHeader1_SiteSearchHeader1_hidGoToaFind_click").value = "1";
			$("SiteHeader1_SiteSearchHeader1_aFind").click();
		}
		return false;
	}
	else return true;
}
function SimpleInputValidate(theText, isEnter, ev)
{	
	if (!isEnter)
	{
		try{
		if (ev)
		{
			if(ev.offsetX < 0 || ev.offsetX >36 || ev.offsetY < 0 || ev.offsetY >19)
				return false;
		}
		else 
		{
			if(ev.pageX - ev.target.offsetLeft < 0 || ev.pageX - ev.target.offsetLeft >36 || 
			ev.pageY - ev.target.offsetTop < 0 || ev.pageY - ev.target.offsetTop >19)
				return false;
		}
		}catch(e){}
	}
		
	objText = $(theText);
	
	msgText = ""
	objText.value = Trim(objText.value)
	if (objText.value.length < 2 && objText.value.length >= 0 || objText.value == $("FIND_FREE_TEXT").value)
	{
		objText.className="InvalidFormField"
		objText.focus();
		if (objText.value.length != 0 && objText.value != $("FIND_FREE_TEXT").value )
			msgText += $("SIMPLEFIND_WRONG_ID").value + "\n"
		else
			msgText += $("SIMPLEFIND_MISSING_TEXT").value + "\n"
	}
	else
	{
		if (!IsOnlyWord(objText.value))
		{
			objText.className="InvalidFormField"
			objText.focus();
			msgText += $("SIMPLEFIND_WRONG_TEXT").value + "\n"
		}else objText.className="FormField"
	}
	
	if (msgText != "")
	{
		alert(msgText);
		return false;
	}
	
	//debugger;
	var URL1 = AppPath + "Templates/searchresult.aspx?Page=1&CProd=20&FN=&FT="+escape(objText.value)+"&FS="+ escape(objText.value) +"&FC=&FSC=&FTC=&FB=&FCH=&FMAX=&FMIN="
	var URL = AppPath + "Templates/searchresult.aspx?Page=1&CProd=20&FN=&FT="+ objText.value +"&FS="+  objText.value +"&FC=&FSC=&FTC=&FB=&FCH=&FMAX=&FMIN="
	
	//URL = escape(URL);
	//alert(URL);
	document.open('text/html',document.location.href);
	document.write('');
	document.close();
	document.location.href=URL;
	window.location.replace(URL1);
	//document.write("<HTML><HEAD><script language='javascript' type='text/javascript' runat='Server'><% Response.Redirect('" + URL + "');%></script></HEAD><body></body></HTML>");
	//window.navigate(URL);
	//document.location.href=URL;
	//document.location=URL;
	return false;
	/*if (!isEnter)
	{
		$("SiteHeader1_SiteSearchHeader1_hidGoToaFind_click").value = "1";
		//$("SiteHeader1_SiteMainMenu1_aFind").click();
	}*/
    //return true;
}


//validate regular search
function CheckInputValidateOnEnter(theText, theCat,theSubCat, theBrand,  ev)
{	
	var characterCode = 0;
	var sender;
	if (ev.which != null) {
		characterCode = ev.which;
		sender = ev.target;
	}
	else {
		characterCode = ev.keyCode;
		sender = ev.srcElement;
	}
    
    if(characterCode == 13) 
    {
		if (InputValidate(theText, theCat,theSubCat, theBrand, true))
		{
			$("SiteSearch1_hidGoTobtnSearch_click").value = "1";
			$("SiteSearch1_btnSearch").click();
		}
		return false;
	}
	else return true;
}
function InputValidate(theText, theCat,theSubCat, theBrand, isEnter, ev)
{	
	if (!isEnter)
	{
		try{
		if (ev)
		{
			if(ev.offsetX < 0 || ev.offsetX >89 || ev.offsetY < 0 || ev.offsetY >29) 
				return false;
		}
		else 
		{
			if(ev.pageX - ev.target.offsetLeft < 0 || ev.pageX - ev.target.offsetLeft > 89 || 
			ev.pageY - ev.target.offsetTop < 0 || ev.pageY - ev.target.offsetTop >29)
				return false;
		}
		}catch(e){}
	}
		
	objText = $(theText);
	objCat = $(theCat);
	objSubCat = $(theSubCat);
	objBrand = $(theBrand);
	
	msgText = ""
	objText.value = Trim(objText.value)
	selectedCategory = objCat.selectedIndex;
	selectedBrand = objBrand.selectedIndex;
	
	selected = selectedCategory + selectedBrand;
	
	if(selected == 0 && (objText.value == "" || objText.value == $("FIND_FREE_TEXT").value) )
	{
		msgText = $("FIND_NO_CHOICE").value + "\n"
		objText.className="InvalidFormFieldRight";
		objCat.className="InvalidFormFieldRight";
		objSubCat.className="InvalidFormFieldRight";
		objBrand.className="InvalidFormFieldRight";	
		
		alert(msgText);
		return false;	
	}	
	else
	{	
		objText.className="FormFieldRight";
		objCat.className="FormFieldRight";
		objSubCat.className="FormFieldRight";
		objBrand.className="FormFieldRight";		
	}	
	if (objText.value.length < 2 && objText.value.length > 0)
	{
		objText.className="InvalidFormFieldRight"
		objText.focus();
		msgText += $("FIND_MISSING_TEXT").value + "\n"
	}
	else
	{
		if (!IsOnlyWord(objText.value)){
			objText.className="InvalidFormFieldRight"
			objText.focus();
			msgText += $("FIND_WRONG_TEXT").value + "\n"
		}
		else objText.className="FormFieldRight"
	}
	
	if (msgText != "")
	{
		alert(msgText);
		return false;
	}
	if (!isEnter)
	{
		$("SiteSearch1_hidGoTobtnSearch_click").value = "1";
	}
	
	return true;
}

//validate advanced search
function AdvInputValidate(theBrand, theCat, theSubCat, theChan, theProdName, theSku, max, min)
{		
	objMax = $(max);
	objMin = $(min);
	objProductName = $(theProdName);
	objProductSku = $(theSku);
	objCat = $(theCat);
	objSubCat = $(theSubCat);
	objChannel = $(theChan);
	objBrand = $(theBrand);
	
	//alert($("hidCatValue").value);
	
	maxValue = objMax.value;
	minValue = objMin.value;
	objProductName.value = Trim(objProductName.value);
	objProductSku.value = Trim(objProductSku.value);
		
	selectedBrand = objBrand.selectedIndex;
	selectedCat = objCat.selectedIndex;
	selectedChannel = objChannel.selectedIndex;
	
	msg = "";
	selected = selectedCat + selectedBrand + selectedChannel;

	if(selected == 0 && objMax.value == "" && objMin.value == "" && objProductName.value == "" && objProductSku.value == "")
	{
		msg += $("FIND_NO_CHOICE").value + "\n";
		objProductSku.className="InvalidFormFieldRight";
		objProductName.className="InvalidFormFieldRight";
		objMax.className="InvalidFormFieldRight";
		objMin.className="InvalidFormFieldRight";	
		objCat.className="InvalidFormFieldRight";
		objSubCat.className="InvalidFormFieldRight";
		objChannel.className="InvalidFormFieldRight";
		objBrand.className="InvalidFormFieldRight";	
				
		alert(msg);
		return false;	
	}	
	else
	{	
		objProductSku.className="FormFieldRight";
		objProductName.className="FormFieldRight";
		objMax.className="FormFieldRight";
		objMin.className="FormFieldRight";
		objCat.className="FormFieldRight";
		objSubCat.className="FormFieldRight";
		objChannel.className="FormFieldRight";
		objBrand.className="FormFieldRight";	
	}
	if(objProductSku.value != '' && isNaN(objProductSku.value))
	{
		objProductSku.className="InvalidFormFieldRight"
		objProductSku.focus();
		msg += $("FIND_WRONG_SKU").value + "\n";
	}
	else objProductSku.className="FormFieldRight"
	
	if(objProductName.value != '' && !IsOnlyWord(objProductName.value))
	{
		objProductName.className="InvalidFormFieldRight";
		objProductName.focus();
		msg += $("FIND_WRONG_NAME").value + "\n";
	}
	else 
	{
		objProductName.className="FormFieldRight";
	}

	var intMaxValue = -1
	var intMinValue = -1
	
	//check max price
	if (IsPrice(maxValue) && maxValue.length > 0)
	{
		objMax.className="FormFieldRight"
		intMaxValue = maxValue * 1
		if (intMaxValue * 1 <= 0)
		{
			//alert (intMaxValue + " <= 0")
			objMax.className="InvalidFormFieldRight"
			msg += $("FIND_MAXPRICE_ZERO").value + "\n"
		}
		else
		{
			//alert (intMaxValue + " > 0")
			objMax.className="FormFieldRight"
		}
	}
	else if (maxValue.length > 0)
	{
		//alert (IsPrice(maxValue) + " IsPrice(maxValue)")
		objMax.className="InvalidFormFieldRight"
		msg += $("FIND_MAXPRICE_NOTNUM").value + "\n"
	}
	
	//check min price
	if (IsPrice(minValue) && minValue.length > 0)
	{
		objMin.className="FormFieldRight"
		intMinValue = minValue * 1
		if (intMinValue * 1 <= 0)
		{
			//alert (intMinValue) + " <= 0")
			objMin.className="InvalidFormFieldRight"
			msg += $("FIND_MINPRICE_ZERO").value + "\n"
		}
		else
		{
			//alert (intMinValue) + " > 0")
			objMin.className="FormFieldRight"
		}
	}
	else if (minValue.length > 0)
	{
		//alert (IsPrice(minValue) + " IsPrice(minValue)")
		objMin.className="InvalidFormFieldRight"
		msg += $("FIND_MINPRICE_NOTNUM").value + "\n"
	}
	
	//check price between
	if ( intMaxValue > 0 &&  intMinValue > 0 &&  intMaxValue !=  intMinValue)
	{
		//alert (intMaxValue + " > 0 &&  " + intMinValue+ "> 0")
		if (intMaxValue <= intMinValue)
		{
			//alert(intMaxValue + " <= " + intMinValue)
			objMax.className="InvalidFormFieldRight"
			objMin.className="InvalidFormFieldRight"
			msg += $("FIND_PRICE_WRONG").value + "\n"
		}
		else
		{
			//alert(intMaxValue + " > " + intMinValue)
			objMax.className="FormFieldRight"
			objMin.className="FormFieldRight"
		}
	}
	if (msg.length > 0)
	{
		alert(msg);
		return false;
    }
    return true;
}


function ReplacePageNumbers()
{	
	var obj = $("ucProducts_PagingTop1_ddlCountProducts");
	if (obj) obj.removeAttribute("language");
	
	var pagingTop = document.getElementById("divPagesTop");
	var pagingBot = document.getElementById("divPagesBottom");
	if (pagingTop != null)// && pagingBot != null 
	{
		if(pagingBot!=null)
		//alert(pagingTop.innerHTML);
		pagingBot.innerHTML = pagingTop.innerHTML;
	}
}
function CheckTalkToFriendForm( auId, absoluteUri, array)
{
	var temp = new Array(); 
	temp = array.split('#'); 
	var emptyStringArray="";
	var wrongStringArray="";
	var urlParam = [];
	urlParam.push('auId');
	urlParam.push('=');
	urlParam.push(auId);
	urlParam.push('&');
	urlParam.push('aUri');
	urlParam.push('=');
	absoluteUri = absoluteUri.replace("?","[1]");
	absoluteUri = absoluteUri.replace("&","[2]");
	urlParam.push(absoluteUri);
	urlParam.push('&');
	
	var reqCount = 0;
	
	for(var i=0;i<temp.length;i=i+3)
	{		
		/*
		v0  txtFirstName.ClientID	- hiddenFirstName.Value - 0
		3  txtFirstName.ClientID	- hiddenFirstNameW.Value - 1
		v6  txtLastName.ClientID	- hiddenLastName.Value - 0
		9  txtLastName.ClientID	- hiddenLastNameW.Value - 1
		v12 txtEmail.ClientID		- hiddenEmail.Value - 0
		15 txtEmail.ClientID		- hiddenEmail.Value - 2
		v18 txtFriendFirstName.ClientID - hiddenFriendFirstName.Value - 0
		21 txtFriendFirstName.ClientID - hiddenFriendFirstNameW.Value - 1
		v24 txtFriendLastName.ClientID	- hiddenFriendLastName.Value - 0
		27 txtFriendLastName.ClientID	- hiddenFriendLastNameW.Value - 1
		v30 txtFriendEmail.ClientID		- hiddenFriendEmail.Value - 0
		33 txtFriendEmail.ClientID		- hiddenFriendEmail.Value - 2
		*/
		
		//checking type of validation
		//0 - not empty string
		//1 - valid string
		//2 - email format
		
		//alert("0 " + i + " " + temp[i] + " - " + document.getElementById(temp[i]).className);
		if(temp[i+2] == "0")
		{
			//create url for ajax
			urlParam.push('p');
			urlParam.push(i);
			urlParam.push('=');
			urlParam.push($(temp[i]).value);
			if (i != 30) urlParam.push('&');
			
			
			if($(temp[i]).value == "")
			{
				reqCount ++;
				emptyStringArray+=temp[i+1]+'\n';
				document.getElementById(temp[i]).className="InvalidFormFieldRight";
			}
			else document.getElementById(temp[i]).className="FormFieldRight";
		}
		//alert("1 " + i + " " + temp[i] + " - " + document.getElementById(temp[i]).className);
		if(temp[i+2]=="1")
		{
			if($(temp[i]).value != "")
			{
				if( !IsOnlyWord($(temp[i]).value))
				{
					//emptyStringArray+=temp[i+1]+'\n';
					wrongStringArray+=temp[i+1]+'\n';
					document.getElementById(temp[i]).className="InvalidFormFieldRight";
				}
				else document.getElementById(temp[i]).className="FormFieldRight";
			}
		}
		//alert("2 " + i + " " + temp[i] + " - " + document.getElementById(temp[i]).className);
		if(temp[i+2]=="2")
		{
			if($(temp[i]).value != "" )
			{
				if(!IsEmailValid($(temp[i]).value))
				{
					//emptyStringArray+=temp[i+1]+'\n';
					wrongStringArray+=temp[i+1]+'\n';
					document.getElementById(temp[i]).className="InvalidFormFieldRight";
				}
				else document.getElementById(temp[i]).className="FormFieldRight";
			}
		}
		//alert("4 " + i + " " + temp[i] + " - " + document.getElementById(temp[i]).className);
	}
	if(reqCount == 6)
	{
		alert("!" + $("ProductImage1_hiddenAll").value);
		return false;
	}
	if(reqCount < 6 && emptyStringArray != "")
	{
		alert(",הנתונים לא תקנים\n " + emptyStringArray);
		return false;
	}
	if(reqCount < 6 && wrongStringArray != "")
	{
		alert(",הנתונים לא תקנים\n " + wrongStringArray);
		return false;
	}
	
	//alert(urlParam.join(''));
	SendTalkToMail(urlParam.join(''));
	return false;
}

function AddToFavorites()
{
	//window.external.AddFavorite(location.href, document.title);
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(document.title, location.href,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( location.href, document.title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
	
}

function SafeBuyPopup() {
	var modalFeatures = "dialogTop=200px; dialogLeft=200px; dialogWidth=600px;dialogHeight=450px; center=yes; help=no;";

	URL = AppPath + "Templates/SafePricePopup.aspx";
	window.showModalDialog(URL, '', modalFeatures);
}
function RelatedProductsPopUp(auctionId) {
	var modalFeatures = "scroll= yes; dialogTop=200px; dialogLeft=200px; dialogWidth=850px;dialogHeight=650px; center=yes; help=no;";
	var winFeatures = "toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=0,width=800,height=650,left = 200,top = 10";

	URL =  AppPath + "Templates/ProductPopUpFrame.aspx?AuctionId="+auctionId;
	window.showModalDialog(URL, '', modalFeatures);
	
	//window.open(URL, '',winFeatures);
}
function SelfPickUpPopUp(supplierId,supplyType) {

	var modalFeatures = "dialogTop=400px; dialogLeft=300px; dialogWidth=200px;dialogHeight=250px; center=yes; help=no; status=no";

	URL = AppPath + "Templates/SelfPickUp.aspx?SupplierId="+supplierId+"&SupplyType="+supplyType;
	
	window.showModalDialog(URL, '',modalFeatures);
}
function ProductWinnersPopUp(productId) {

	var modalFeatures = "dialogTop=100px; dialogLeft=300px; dialogWidth=430px;dialogHeight=550px; center=yes; help=no; status=no";

	URL = AppPath + "Templates/ProductWinnersPopUp.aspx?productId="+productId;
	window.showModalDialog(URL, '',modalFeatures);
}
function OrderSelfPickUpPopUp(auctionId)
{
	var modalFeatures = "toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,dialogWidth=600,dialogHeight=500,dialogLeft = 290,dialogTop = 200";

	URL = AppPath + "Templates/OrderSelfPickUpFrame.aspx?AuctionId="+auctionId;
	window.showModalDialog(URL, '','');
	
	var loc = window.location.href ;
	loc = loc.replace('&trmuse=1','');
	if ($('chkAgreement').checked)
		loc = loc + "&trmuse=1"
	else loc = loc.replace('&trmuse=1','');
	return true;
	//__doPostBack('CheckOutProducts1$repProd$_ctl1$ddlPayments','')
	//document.FormOrderCheckOut.submit();
	//window.location.replace(loc);
}
function CrossSalePopUp(auctionId) {
	var winFeatures = "toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=820,height=600,left = 100,top = 10";

	URL = AppPath + "Templates/ProductPopUp.aspx?AuctionId="+auctionId;
	//window.showModalDialog(URL, "", modalFeatures);
	window.open(URL, '',winFeatures);
}
function ComplaintPopUp(tafnitOrder, productID, arutzOrder) {

	var modalFeatures = "dialogTop=400px; dialogLeft=300px; dialogWidth=520px;dialogHeight=400px; center=yes; help=no; status=no";

	URL = AppPath + "Templates/ComplaintFrame.aspx?tafnitOrder="+tafnitOrder+"&productID="+productID+"&arutzOrder="+arutzOrder;
	window.showModalDialog(URL, '',modalFeatures);
}

function TvLive() {
	URL = AppPath + "Templates/21Online.aspx";
	window.open(URL, '', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=500,left = 490,top = 150');
}
function OpenWinSSL(){
	self.open("https://www.thawte.com/cgi/server/certdetails.exe?referer=http://www.21.tv","ssl","resizable=yes,scrollbars=no,height=630,width=500");
}
function GotoPage(url)
{
	window.document.location.replace(url);
}
function UserOpinionValid(form)
{
	var retVal = true;
	var err = "בחר/בחרי כן/לא";
	if (!form.rbBuy_0.checked && !form.rbBuy_1.checked)  
	{	
		retVal = false;
		$("lblBuy1").innerText = err;
	}
	else $("lblBuy1").innerText = "";
	if (!form.rbSatisfied_0.checked && !form.rbSatisfied_1.checked)  
	{	
		retVal = false;
		$("lblSatisfied1").innerText = err;
	}
	else $("lblSatisfied1").innerText = "";
	if (!form.rbSatisfied_0.checked && !form.rbOnTime_1.checked) 
	{	
		retVal = false;
		$("lblOnTime1").innerText = err;
	}
	else $("lblOnTime1").innerText = "";
	if (!form.rbFix_0.checked && !form.rbFix_1.checked)  
	{	
		retVal = false;
		$("lblFix1").innerText = err;
	}
	else $("lblFix1").innerText = "";
	if (!form.rbService_0.checked && !form.rbService_1.checked) 
	{	
		retVal = false;
		$("lblService1").innerText = err;
	}
	else $("lblService1").innerText = "";
	if (!form.rbServiceOK_0.checked && !form.rbServiceOK_1.checked) 
	{	
		retVal = false;
		$("lblServiceOK1").innerText = err;
	}
	else $("lblServiceOK1").innerText = "";
	if (!form.rbOrderProcsess_0.checked && !form.rbOrderProcsess_1.checked) 
	{	
		retVal = false;
		$("lblOrderProcsess1").innerText = err;
	}
	else $("lblOrderProcsess1").innerText = "";
	if (!form.rbSearch_0.checked && !form.rbSearch_1.checked) 
	{	
		retVal = false;
		$("lblSearch1").innerText = err;
	}
	else $("lblSearch1").innerText = "";
	if (!form.rbBack_0.checked && !form.rbBack_1.checked)  
	{	
		retVal = false;
		$("lblBack1").innerText = err;
	}
	else $("lblBack1").innerText = "";
	if (!form.rbRecommend_0.checked && !form.rbRecommend_1.checked)
	{	
		retVal = false;
		$("lblRecommend1").innerText = err;
	}
	else $("lblRecommend1").innerText = "";
	if (!retVal) alert(form.hidError.value);
	return retVal;
}
function ShowHideDiv(id)
{
	if(id=="ProductImage1_ImageId")
	{
		$("ProductImage1_ImageId").setAttribute("src","../Images/ItemTabsImageOn.gif");
		if($("ProductImage1_VideoId")) $("ProductImage1_VideoId").setAttribute("src","../Images/ItemTabsVideoOff.gif");
		$("ProductImage1_RecomendId").setAttribute("src","../Images/ItemTabsRecommendOff.gif");
		$("ProductImage1_iframeVideo").setAttribute("src", "");
		//alert( $("ProductImage1_iframeVideo").getAttribute("src") +"(())"+ $("ProductImage1_iframeVideo").getAttribute("datafld"))
		ImageDiv.style.display="block";
		VideoDiv.style.display="none";
		RecomendDiv.style.display="none";
	}
	else if(id=="ProductImage1_VideoId")
	{
		if($("ProductImage1_VideoId")) $("ProductImage1_VideoId").setAttribute("src","../Images/ItemTabsVideoOn.gif");
		$("ProductImage1_RecomendId").setAttribute("src","../Images/ItemTabsRecommendOff.gif");
		$("ProductImage1_ImageId").setAttribute("src","../Images/ItemTabsImageOff.gif");
		$("ProductImage1_iframeVideo").setAttribute("src", $("ProductImage1_iframeVideo").getAttribute("datafld"));//"http://switch5.castup.net/cuplayer.asp?customer=skin_castup_blue&amp;source=volume&amp;Display.ToolbarStyle=live&amp;clip.nb=35541");
		//alert( $("ProductImage1_iframeVideo").getAttribute("src") +"(())"+ $("ProductImage1_iframeVideo").getAttribute("datafld"))
  		ImageDiv.style.display="none";
		VideoDiv.style.display="block";
		RecomendDiv.style.display="none";
	}
	else
	{
		$("ProductImage1_RecomendId").setAttribute("src","../Images/ItemTabsRecommendOn.gif");
		$("ProductImage1_ImageId").setAttribute("src","../Images/ItemTabsImageOff.gif");
		if($("ProductImage1_VideoId")) $("ProductImage1_VideoId").setAttribute("src","../Images/ItemTabsVideoOff.gif");
		$("ProductImage1_iframeVideo").setAttribute("src", "");
		//alert( $("ProductImage1_iframeVideo").getAttribute("src") +"(())"+ $("ProductImage1_iframeVideo").getAttribute("datafld"))
		ImageDiv.style.display="none";
		VideoDiv.style.display="none";
		RecomendDiv.style.display="block";
	}
}
// -----------------OPEN BIG IMAGE FOR PRODUCT--------------------------------------
winX =100;winY =100;
winXW=550;winYH=600;

if (parseInt(navigator.appVersion.charAt(0))>=4){
	isFF=(navigator.appName=="Netscape")?1:0;
	isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}

optFF='toolbar=no,scrollbars=no,width='+winXW+',height='+winYH+',left='+winX+',top='+winY+',minimize=no,resizable=no,status=no';
optIE='toolbar=no,scrollbars=no,width='+winXW+',height='+winYH+',left='+winX+',top='+winY+',minimize=no,resizable=no,status=no';

var imageURL;
var imageTitle;
var prevImageId;
function popImage(){
	if (isFF){imgWin=window.open('about:blank','',optFF);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}

	with (imgWin.document){
		writeln('<html><head><title>' + imageTitle + '</title><style>body{margin:0px;}');
		writeln('a.smallImageLink{display: block; width: 77px; height: 69px; padding: 15px 0px 5px 0px; background: url(../Images/smallImg_bg.gif) left top no-repeat; text-decoration: none; text-align: center;}');
		writeln('a.smallImageLink_selected{display: block; width: 77px; height: 69px; padding: 15px 0px 5px 0px; background: url(../Images/smallImg_bg.gif) left 84px repeat-y; text-decoration: none; text-align: center;}');
		writeln('</style>');
		writeln('<sc'+'ript>');
		writeln('var isFF,isIE;');
		writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isFF=(navigator.appName=="Netscape")?1:0;');
		writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function FixSize(){');
		writeln('if (isIE){');
		writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');
		writeln('if (isFF){');       
		writeln('window.innerWidth=document.images["tv21"].width;');
		writeln('window.innerHeight=document.images["tv21"].height;}}');
		writeln('function SetTitle(){document.title="'+imageTitle+'";}');
		writeln('var prevImageId="'+prevImageId+'"');
		writeln('</sc'+'ript>');
		writeln('<script language="javascript" type="text/javascript" src="' + AppPath + 'ClientScripts/Main.js"></script>');
		writeln('</head><body bgcolor=white scroll="yes" onload="FixSize();SetTitle();self.focus()">');
		writeln('<div align="center"><div style="width: 500px;height: 500px;"><img id="tv21" name="tv21" src='+imageURL+' style="display:block"></div>');
		if ($('tblSmallImages'))
		{
			var innerhtm = $('tblSmallImages').outerHTML
			//innerhtm = innerhtm.replace("<tr>", '<tr><td width="100%" ></td>');
			writeln(innerhtm);
			
		}
		writeln('</div></body></html>');
	}
	
	return false;
}

function replaceImage(smallImg, imgId, newSrc, bigSrc)
{
	if(document.getElementById(imgId))
	{
		document.getElementById(imgId).src = newSrc;
		if (document.getElementById(prevImageId)) 
		{
			if(document.getElementById(prevImageId).parentElement)
				document.getElementById(prevImageId).parentElement.className = "smallImageLink";
			else document.getElementById(prevImageId).parentNode.className = "smallImageLink";
		}
		if (smallImg.parentElement)
			smallImg.parentElement.className = "smallImageLink_selected";
		else smallImg.parentNode.className = "smallImageLink_selected";
		prevImageId = smallImg.id;
		imageURL = bigSrc;
	}
	else 
	{
	//debugger;
		if (document.getElementById('tv21'))
		{
			document.getElementById('tv21').src = bigSrc;
			if (document.getElementById(prevImageId)) 
			{
				if(document.getElementById(prevImageId).parentElement)
					document.getElementById(prevImageId).parentElement.className = "smallImageLink";
				else document.getElementById(prevImageId).parentNode.className = "smallImageLink";
			}
			if (smallImg.parentElement)
				smallImg.parentElement.className = "smallImageLink_selected";
			else smallImg.parentNode.className = "smallImageLink_selected";
			prevImageId = smallImg.id;
			imageURL = bigSrc;		
		}
	}
}

function PoupAutoBid()
{	
	window.scrollTo(0,0);

	$('ddlAutoBidValue').options.length = 0;
	$('ddlAutoBidValue').disabled = false;
	$('ddlAutoBidValue').options[0] = new Option("ללא הצעה אוטומטית","");	
	
	var bidAddon = document.getElementById("hidBidStep").value;
	var curPrice = document.getElementById("CurrentPrice").innerText;
	var listPrice = document.getElementById("hidLPrice").value;
	var userSelectedAB = document.getElementById("PricesBuilder1_hidUserAutoBidPrice").value;

	var finParam = curPrice + ";" + bidAddon + ";"+ listPrice + ";" +userSelectedAB;
	//alert(finParam);
	var index = 1	
	
	curPrice = parseInt(curPrice) + (parseInt(bidAddon) * 2);
	
	if (parseInt(curPrice) >= parseInt(listPrice))
	{
		listPrice = parseInt(curPrice) + (parseInt(bidAddon) * 3);
	}
	for(i= parseInt(curPrice); i < parseInt(listPrice); i = i + parseInt(bidAddon))
	{
		if (userSelectedAB == i)
			$('ddlAutoBidValue').options[index] = new Option(i,i,false,true);
		else 
			$('ddlAutoBidValue').options[index] = new Option(i,i);
		index++;
	}
	$('divAutoBid').className ="AutoBidOn";
}
//----------------------------------------------------------------------
var ajaxSendMail;
function SendTalkToMail(params)
{	
	var url = "../Services/SendMail.aspx?"+ params;
	ajaxSendMail = new AjaxClient();
	ajaxSendMail.Get(url,AjaxClientCallback);
}


function AjaxClientCallback()
{	
	//ensure corrent response
	if(ajaxSendMail != null && ajaxSendMail.Http.readyState == 4 && ajaxSendMail.Http.status == 200)
	{
		var status = ajaxSendMail.Http.responseText;
		
		if (status != null)
		{
			var statusArr = status.split('#');
			if (statusArr[0] == "true")
			{
				$("ProductImage1_lblSended").innerText = statusArr[1];
				$("ProductImage1_txtFirstName").value = "";
				$("ProductImage1_txtLastName").value = "";
				$("ProductImage1_txtEmail").value = "";
				$("ProductImage1_txtFriendFirstName").value = "";
				$("ProductImage1_txtFriendLastName").value = "";
				$("ProductImage1_txtFriendEmail").value = "";
			}
			else
			{
				$("ProductImage1_lblSended").innerHTML = statusArr[1];
			}
		}
	}	   	   
}
