var sFormName	   = '';
var sVirtualDir    = '';
var postFixListObj = '_ListObjects';
/*
Next Flag is a late addition. it's for cleaning the markMode whenever the user clicks
the search button (regular search) - in use in Search.aspx		*/
var flagInvokedByMarked = ''

/**********************************************************************************************************************/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/**********************************************************************************************************************/
//22012009	MM_preloadImages('images/general/radio2.gif', 'images/general/check2.gif')
//22012009	var imgClicked     = new Array("images/general/check1.gif", "images/general/radio1.gif")
//22012009	var imgSrcClicked  = new Array("images/general/check2.gif", "images/general/radio2.gif")

/**********************************************************************************************************************/
function set_sVirtualDir4HtmlControl(val_sVirtualDir) {
	sVirtualDir = val_sVirtualDir
	}
/**********************************************************************************************************************/
function set_sFormName4HtmlControl(val_sFormName) {
	sFormName = val_sFormName
	}
/**********************************************************************************************************************/

function ChooseBranch(formName, txtName, txtID)
{
	feat = "resizable=yes,width=670,height=500";
	url = "Util/SubBranches2.aspx?formName=" + formName + "&txtName=" + txtName.name + "&txtID=" + txtID.name;
	window.open (url, "newBranch", feat);
}
/**********************************************************************************************************************/
//this func replaces HtmlInputClicked() for Radios
function RadioClick(rdObj, obj, val){
	var oListNames = eval(sFormName + "." + rdObj.name + postFixListObj)
	rdObj.value = val
	oListNames.value = obj.id
	//alert(rdDynmicDate.value)
}
/**********************************************************************************************************************/
//this func should replace HtmlInputClicked() after we get reed of all the img-checkBox
function InputClicked2(rdObj, obj, val){
			
	var oListNames = eval(sFormName + '.' + rdObj.name + postFixListObj)
	if(obj.checked)
		{
		if (rdObj.value != '') 
			{
			rdObj.value += ','
			oListNames.value += ','
			}
		//add name and ID
		rdObj.value += val
		oListNames.value += obj.id
		}
	else
		{
		// remove the current false-checked :
		rdObj.value = RemoveFromString(rdObj.value, val)
		oListNames.value = RemoveFromString(oListNames.value, obj.id)
		}
}
		
		
/**********************************************************************************************************************/
//this is for the dates, we format them onBlur,
//obj = form object, val = value of the field:
function formatDate(obj , val) {
	alert_an_error = false
	val = vbs_replace(val,"-","/")
	val = vbs_replace(val,".","/")
	val = vbs_replace(val," ","/")
	val = vbs_replace(val,"\\","/")
	var temp = val

	if (val !='')
		{
		if ( val.indexOf("/")== -1)
			{
			temp = val.substring(0,2) + "/" + val.substring(2,4)
			if (isFinite(val.substring(0,2)) == true && isFinite(val.substring(2,4)) == true)
				{
				if (val.length >= 6)
					{
					temp +=  "/" + val.substring(4,val.length)	
					if (isFinite(val.substring(4,val.length)) == false)
						{
						alert(message_format)	
						alert_an_error = true
						}
					}
				else
					{
					obj.value = temp
					alert(message_format)	
					alert_an_error = true
					}
				}
			else
				{
				alert(message_format)
				alert_an_error = true
				}
			}	
		else //val.indexOf("/")> -1
			{
			if (val.length < 6)
				{
				obj.value = temp
				alert(message_format)
				alert_an_error = true
				}
			}
		}
	//assign it:
	obj.value = temp

	if (alert_an_error != true && temp !='')
		{
		//check if valid:
		validDate(temp)
		
		if (alert_an_error)	
			obj.value = ""
		}
	if (alert_an_error)	obj.focus()	
}

/**********************************************************************************************************************/
//This func should replace markImgCb after we get reed of all the img-CheckBox
function markCb(dir) {
	for (var i=0; i<=cbImgArray.length-1; i++) 	{
		current_ch = eval(sFormName + "." + cbImgArray[i])
		if (current_ch)								// just to fix a bug - when we delete an item.
		
			if (current_ch.checked != dir )
				{
				current_ch.click()
				}
	}
}

/**********************************************************************************************************************/
function ShowTender(infoID, changeAction)
{
	if (changeAction) {
		//alert(eval(sFormName).__VIEWSTATE.name)
		eval(sFormName).__VIEWSTATE.name = "abc"  //"Search_VIEWSTATE" //<%-- 21.9.2008 cancel svs --%>
		//eval(sFormName).__EVENTARGUMENT.name = "Search_EVENTARGUMENT"	
		eval(sFormName).action = "showTender.aspx"
		}

	eval(sFormName + ".infoID").value = infoID
	eval(sFormName).action = "ShowTender.aspx"
	eval(sFormName).submit()
}
//////////////////////////////////////////////////////////////
function openUrl() {
	feat = "top=10,scrollbars=yes,width=575,height=600"
	window.open("http://www.tenders.co.il/Banner12/html/mivza.asp", "nam", feat)
}
//////////////////////////////////////////////////////////////
function abList(FormName) {
	feat = "top=10,scrollbars=yes,width=450,height=305"
	window.open("util/AbList.aspx?searchPharse=" + frSearch.txtPublisher.value + "&OpenerFormName=" + FormName, "ab", feat)
}
/**********************************************************************************************************************/
//By JavaScript Kit (http://www.javascriptkit.com)
//Over 200+ free scripts here!
function CheckEmail(EmailObj){
	//EmailObj.value = Trim(EmailObj.value)
	var Filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	arr = EmailObj.value.split(";")
	for (var i=0;i<=arr.length-1;i++){
		if (!(Filter.test(arr[i])) && arr[i] !=''){
			alert(IllegalMail)
			EmailObj.focus()	
			return
		}
	}
}
//////////////////////////////////////////////////////////////
function del_reminer(ReminderID, aClick) {
	if (confirm(DelRemindrMsg))
		{
		eval(sFormName).delReminderID.value = ReminderID
		
		if (aClick) 
			aSearch.click()
		else
			{
			eval(sFormName).action = ''
			eval(sFormName).__VIEWSTATE.name = 'old__VIEWSTATE'
			eval(sFormName).submit()
			}		
		}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function formatTime(obj ,vali , alertIT)
{
	err = false
	str = vali
	if (vali=="")
		{
		//err = true
		}
	else
		{
		alertIT = true
		if (vali.length == 4)
			{
			if (vali.indexOf(":")==-1)
				str = vali.substring(0,2) + ":" + vali.substring(2,4)
				err = false
			}
		else
			{
			if (vali.length==5 && vali.indexOf(":")>-1)
				{//that is ok:
				err = false
				}
			else
				{
				if (vali.length == 3)
					{
					str = vali.substring(0,1) + ":" + vali.substring(1,4)
					}
				else
					{
					err = true
					}
				}
			}
		}

	if (alertIT==true && err == true)
		{
		alert(PleaseGoodTime)
		obj.focus()
		}
	else
		{
		//that is ok, check time:
		if (check_time(str)==false)
			{
			alert(PleaseGoodTime)
			obj.focus()
			}
		}
	obj.value = str
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function check_time(time)
{
rValue = false
tempi = time.split(":")

if (time!="")
{
	if (tempi.length==2)
		{
		if (isFinite(tempi[0])&& isFinite(tempi[1]))
			{			
			if (tempi[0] >=0 && tempi[0] <= 24 && tempi[1] <=59 && tempi[1] >=0)
				{
				rValue = true	
				}
			else
				rValue = false
			}
		else
			rValue = false
		}
	else
		rValue = false
		
}
else
	rValue = true

return rValue
}
//////////////////////////////////////////////////////////////
function checkIfAnyMarked() {
	return (eval(sFormName + ".cbInfos").value != "")
}
//////////////////////////////////////////////////////////////
function checkIfMarkedLinkValid() {
    if (!checkIfAnyMarked())
		{
		alert(NoOneMarkedMsg)
		event.returnValue = false
		}	
}
//////////////////////////////////////////////////////////////
function reminder(infoIDs, ReminderID) {

	var feat = "left=" + (screen.availWidth * 1/5) + ",top=" + (screen.availHeight*1/4)
	var widthFeat = "width=750,height=432,"
	
	if (ReminderID !="" && ReminderID != "-1")
		url = "Util/ppReminders.aspx?ReminderID=" + ReminderID
	else	
		if (infoIDs == "-1")	
			{
			url = "Util/ppReminders.aspx?defaults=yes"
			widthFeat = "width=750,height=335,"
			}
		else	
			url = "Util/ppReminders.aspx?txtInfoIDs=" + infoIDs
		
	feat = widthFeat + feat + ",resizable=yes"
	window.open(url, "winiRem", feat)
}
//////////////////////////////////////////////////////////////
function js_GetDate_diri(diri, sFieldName) {
	GetDate_diri(diri, sFieldName)
}
//////////////////////////////////////////////////////////////
function append(oldStr, newVal, delimter) {
	if (oldStr !="")
		oldStr += delimter
	oldStr += newVal
	return oldStr
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function printDoc(s_isPrintState)
{
	oSFormName = eval(sFormName)

	// save for later update back:
	old_action = oSFormName.action + ""

	var sInfo = oSFormName.cbInfos.value
	// take from function params: s_isPrintState = "yes"
	if (sInfo == '') 
		{
			alert (NoOneMarkedMsg)
			return 
		}

	oSFormName.__VIEWSTATE.name = "temp_VIEWSTATE"
	oSFormName.isPrintState.value = s_isPrintState
	oSFormName.target = "_new"
	oSFormName.action = "Search.aspx"
	oSFormName.submit()

	//init back:
	oSFormName.action = old_action
	oSFormName.target = ""
	oSFormName.isPrintState.value = ''
	oSFormName.__VIEWSTATE.name = "__VIEWSTATE"
}
//////////////////////////////////////////////////////////////


function marked(mode, objClick) {

    if (mode=='marked' && !checkIfAnyMarked())
		{
		alert(NoOneMarkedMsg)
		return 
		}	
	else {
		eval(sFormName).markMode.value = mode
		if (objClick==null)	
			eval(sFormName).submit()
		else {
			flagInvokedByMarked = 'yesIndeed'
			objClick.click()
		}
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Next three Trim functions "as is" from www.apriori-it.co.uk
//They also have some good date validators and popup calender
function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
	return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
	return "";
	}
	else{
	return TRIM_VALUE;
	}
} 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
	return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
		strTemp = VALUE.substring(0,iTemp +1);
		break;
		}
		iTemp = iTemp-1;
	} 
	return strTemp;
} 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
	return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
		strTemp = VALUE.substring(iTemp,v_length);
		break;
		}
		iTemp = iTemp + 1;
	} 
	return strTemp;
} 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 22012009
function HtmlInputClicked(rdObj, obj, isRadio, val, str2Restore){
	var oListNames = eval(sFormName + "." + rdObj.name + postFixListObj)

	if (isRadio)
		{
		// save the value for the post:
		if (str2Restore!="") RadioRestoreList(str2Restore)
		rdObj.value = val
		// save the object name for later posting:
		oListNames.value = obj.id
		}
	else	
		{
		if (rdObj.value!="") 
			{
			rdObj.value += ","
			oListNames.value += "," // save the object names for later posting.
			}
		rdObj.value += val
		
		// save the object names for later posting:
		oListNames.value += obj.id
		}

	
	if (obj.src.indexOf(imgClicked[isRadio])>0)
		{
		if (!isRadio)
			{
			rdObj.value = RemoveFromString(rdObj.value, val)
			// save the object names for later posting (remove the current false-checked):
			oListNames.value = RemoveFromString(oListNames.value, obj.id)
			}
			
		obj.src = sVirtualDir + imgSrcClicked[isRadio]
		}
	else
		{
		obj.src = sVirtualDir + imgClicked[isRadio]	
		}
}*/
//--------------------------------------------------------------------------------------------
/* 22012009
function RadioRestoreList(sRadio)
{
arr_arrRadioList = sRadio.split(",")
for (var i=0; i<=arr_arrRadioList.length-1; i++)
	{
	eval(sFormName + "." + arr_arrRadioList[i]).src = imgSrcClicked[1];
	}
}*/
/**********************************************************************************************************************/
function ResetCheckBoxs(objList)
{
if (objList.value != '')
	{
	var arrCbListObj = objList.value.split(',')
	for (var i=0; i<=arrCbListObj.length-1; i++)
		{
		eval(sFormName + "." + arrCbListObj[i]).click()
		}
	}	
}

/**********************************************************************************************************************/
var cbImgArray = new Array();
function saveCbInArray(objName) {
	// save the object:
	cbImgArray[cbImgArray.length] = objName;
}

/**********************************************************************************************************************/
/* Mark or UnMark the Img-Html Checkboxes: */
/*function markImgCb(dir) { 
	if (dir)
		new_image = imgClicked[0]
	else
		new_image = imgSrcClicked[0]
	for (var i=0; i<=cbImgArray.length-1; i++) 	{
		current_image = eval(sFormName + "." + cbImgArray[i])
		
		if (!(current_image.src == undefined))	// just to fix a bug - when we delete an item.
			if (current_image.src.indexOf(new_image) == -1 )
				{
				current_image.click()
				}
	}
}*/
/**********************************************************************************************************************/
function RestoreValues(oValue)
{
var str = oValue.value
var oList = eval(sFormName + '.' + oValue.id + postFixListObj)
var listString = oList.value

if (listString != '')
	{
	arr = listString.split(',')
	for (var i=0; i<=arr.length-1; i++)
		{
		if (arr[i] != '')
			{
			try {
					if(! eval(sFormName + "." + arr[i]).checked){
						if (eval(sFormName + "." + arr[i]).type == 'radio')
							eval(sFormName + "." + arr[i]).click()
						else{
							eval(sFormName + "." + arr[i]).checked = true
							//alert(sFormName + "." + arr[i])
							}
					}
				}
			catch(e) {
				//alert(e.message)
				}
			}
		}
	}
}
/**********************************************************************************************************************/
function RemoveFromString(Obj_value, val)
{
var sRet = ''
var arr_str = Obj_value.split(",")
for (var i=0; i<=arr_str.length-1; i++)
	{
	if (val != arr_str[i])
		if (sRet == '')
			sRet = arr_str[i]
		else
			sRet += "," + arr_str[i]
	}	
return sRet;
}

/**********************************************************************************************************************/
/* Box actions - add/remove from Box. */
function BoxAction(sAction, oForm, slistInfo, goToMTP)
{
	var windowName = sAction + "newWin"
	var feat = "width=231,height=70,left=" + (screen.availWidth * 1/3) + ",top=" + (screen.availHeight*1/3)
	var temp_viewState_value
	/*10122008 canceled also in main-index*/
	if (slistInfo=='') 
	{
		if (sAction != 'box_del'){
			alert(NoOneMarkedMsg)
			return
		}
		/*else{
			if (confirm("לא נבחרו מכרזים לפעולה\n?האם לבצע הפעולה על כל המכרזים"))
				{				}
			else
				return 
		}*/
	}

// save and free settings before submit:
temp_viewState_value    = oForm.__VIEWSTATE.value
oForm.__VIEWSTATE.value = ""
oForm.__VIEWSTATE.name  = "temp_VIEWSTATE"

// submit page:
window.open("Util/Wait.html", windowName, feat)
oForm.target = windowName
oForm.method = "post"
oForm.action = "Util/ppBoxActions.aspx?goToMTP=" + goToMTP + "&Action=" + sAction
oForm.submit()

//restore initial settings of the form:
//alert(temp_viewState_value	)
oForm.__VIEWSTATE.name = "__VIEWSTATE"
oForm.__VIEWSTATE.value = temp_viewState_value
oForm.action = ""
oForm.target = ""
}

/**********************************************************************************************************************/
/* שתי הפונקציות הבאות הן טלאי לתיקון בג שהיה בעמוד אינדקס
מטרתן לבחור הכל אם המשתמש לחץ על הוסף לתיבה מבלי לסמן רשומות
ואחר כך לשחרר הכל. זה קצת מסורבל אבל המטרה היא לעשות את התיקון
בלי לשנות את הפונקציות הקיימות שעובדות בסדר במספר דפים   */
/* 10122008 cancel this option
var flagUncheckAll = false
function BeforeBoxActionIndex(slistInfo){
	if (slistInfo==''){
		if (confirm("לא נבחרו מכרזים לפעולה\n?האם לבצע הפעולה על כל המכרזים")){
			flagUncheckAll = true
			markCb(1)
			}
		} 
}
function AfterBoxActionIndex(){
	if (flagUncheckAll == true){
	markCb(0)}
}*/

//18.8.2009 Moved from VbMiscNew.vbs
function vbsIsDate(sDate) {
	//17.8.2009 trying to get rid of the vb script
	var scratch = new Date(sDate);
	if (scratch.toString() == "NaN" || scratch.toString() == "Invalid Date")
		return false; 
	else 
		return true;
}
//18.8.2009 Moved from VbMiscNew.vbs
function GetDate_diri(diri, sFieldName){
	var sParam;
	arrIndex = -1;
	sParam = "";
	sParam = window.showModalDialog(diri + "Util/Behavior_date/Calendar.htm","", "dialogHeight:225px;dialogWidth=300px;help=no;status=no;")	
	document.all(sFieldName).value = sParam;
}
//18.8.2009 Moved from VbMiscNew.vbs
function GetDate(sFieldName){
	GetDate_diri ("", sFieldName);
}