
function setColor(el, bg) {
  if (el.style) el.style.backgroundColor = bg;
}

function RedirectAddingQuestion(sSendQuestionURL)
{
	location.href=sSendQuestionURL ;
}

function printFaq(sQuestionGuid)
{
	 var url = "/Purchasing/Pages/Purchasing/FaqPrintPage.aspx?Guid=" + sQuestionGuid;
	 window.open(url,'mywindow','width=400,height=450,resizable=yes,scrollbars=yes');
	 
}
	 

function DeleteStatus(status)
{
	alert(status);
}
	
function ConfirmDeleteAjax(msg,deletePostingGuid)
{
	
	if (confirm(msg)){
		
		var url = 'http://localhost/Purchasing/Ajax/Purchasing/AjaxPostingMangement.aspx';
		 AJAX.asyncWithCallback(url, "posingGuid="+deletePostingGuid, DeleteStatus, false, false, null) ; 
		 window.location.reload( false );
	}
}
function checkForm(mform)
{
	var ruvalid = "";
	var bgNotValid ="#ecf4c1";//    //background color after change   "#ecf4c1"- a light green#FFC993
	var bgValid = "white";  //basic background color
	var lo_col=document.getElementsByTagName("INPUT");
	var ll_col_len=lo_col.length;
	for (i=0;i<ll_col_len;i++)  
	{
		var lo_field=lo_col[i];
		if(lo_field.IS_REQUIRED=="true" && lo_field.value=="")
		{
			ruvalid += "???? "+lo_field.DESC+" ??? ??? ????"; 
			setColor(lo_field, bgNotValid);
		}
			
		if(lo_field.type=="file"){
			if(!checkField(lo_field))
				return(false);
		}
		
	}
	
	if(ruvalid != "" ) {
		alert("????? ?? ?????!\n---------------------\n" + ruvalid);
		return(false);
	} 
	
	
	return(true);
}

function isHebrewChar(str) 
{ 
  var strInvalid = "??????????????????????????"; 
  var thisChar;
  for(var i =0;i< str.length;i++) 
  { 
    thisChar = str.substring(i,i+1); 
    if(strInvalid.indexOf(thisChar) != -1) 
    {  	
     	return true; 
    } 
  } 
  return false;   
} 

function resetForm()
{
	document.forms[0].reset();
	var obj = document.getElementsByTagName("input");			
	for (i = 0 ; i < obj.length ; i++)
	{
		if((obj[i].type == "text"))
		{
			obj[i].value = "";
		}
	}
}

function ButtonRoll(id)
{
	var button = document.getElementById(id);
	if (!(button.src.indexOf('roll') > -1))
	{
		if (button.src.indexOf('click') > -1)
		{
			button.src =  button.src.replace("_click.gif","_roll.gif"); 
		}
		else
		{
			button.src =  button.src.replace(".gif","_roll.gif"); 
		}
	}
}

function ButtonClick(id)
{
	var button = document.getElementById(id);
	button.src = button.src.replace("_roll.gif","_click.gif");
}

function ButtonOut(id)
{
	var button = document.getElementById(id);
	if ((button.src.indexOf('roll') > -1))
	{
		button.src = button.src.replace("_roll.gif",".gif");
	}
	if ((button.src.indexOf('click') > -1))
	{
		button.src = button.src.replace("_click.gif",".gif");
	}
}

function check_str(field)
{
	var index=field.lastIndexOf("\\");
	if(index>-1)
		str=field.substring(index+1,field.length);
	else
		str=field;
	if (isHebrewChar(str)){
		alert(" ?? ????? :\n\""+str+"\"\n???? ?????? ?????? ???? ?? ???? ????? ????");
		return false;
	}
	if(str.indexOf(' ')>=0){
		alert(" ?? ????? :\n\""+str+"\"\n???? ?????? ???? ?? ???? ????? ????");
		return (false);
	}	
			
	return true;	
}		
function checkField(formField)
{
	var result=check_str(formField.value);
	if(!result){
		formField.focus();
		return(false);
	}
	return true;
}

function openLogin()
{
	window.open('deshe.asp?cat=homepage&script=login&popup=1','login','height=200,width=300');
}

function isChar(val,args) 
{ 
  var strValid = "??????????????????????????? -'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
  var thisChar;
  for(var i =0;i < args.length;i++) 
  { 
    thisChar = args.substring(i,i+1); 
    if(strValid.indexOf(thisChar) == -1) 
    {  	
     	return false; 
    } 
  }
  return true; 
}

function ValidatePage(){
	//check if mail is valid
	var mesg="";
	sendFormToValue = document.getElementById("InputEMail").value;
	var valid_email = "";
	valid_email = sendFormToValue.search(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
	
	// helper parameters
	var strValid = "??????????????????????????? -'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
    var thisChar;
	
	//check if first name is valid
	var firstName = document.getElementById("InputFirstName").value;
	var valid_first_name = "";
	valid_first_name = (firstName == "");

	// check that the first name has the format of characters
	for(var i =0; i < firstName.Value.length; i++) 
	{ 
		thisChar = firstName.Value.substring(i,i+1); 
		if(strValid.indexOf(thisChar) == -1) 
		{  	
     		valid_first_name = false; 
		} 
	} 
	
	
	//check if last name is valid
	var lastName = document.getElementById("InputLastName").value;
	var valid_last_name = "";
	valid_last_name = (lastName == "");
	
	// check that the first name has the format of characters
	for(var j =0; j < lastName.Value.length; j++) 
	{ 
		thisChar = lastName.Value.substring(j,j+1); 
		if(strValid.indexOf(thisChar) == -1) 
		{  	
     		valid_last_name = false; 
		} 
	}
	
	var valid_mail;
	//alert("valid_email: " + valid_email);
	if (valid_first_name) {
		mesg = mesg + "?? ???? ?? ???? ?? ?? ???? ???? ????\n";
	} 
	if (valid_last_name) {
		mesg = mesg +"?? ???? ?? ????? ?? ?? ????? ???? ????\n";
	}
	
	if (sendFormToValue != "") {
		// has a value, then validate it	
		if(valid_email==-1){
			mesg = mesg + "?? ???? ????? ???? ?????\n";
			valid_mail = false;
		}
		else{
			valid_mail = true;
		}
	} else {
		valid_mail = true;
	}
	
	// reporting error message if exists
	if(mesg!="") {
		alert(mesg);
		return false;
	}
	else 
	{
		return true;
	}
}

function setValue(currPage,cntrlID)
{
	
	if (document.getElementById(cntrlID+"_TextBox1") == null)
	{
		document.getElementById(cntrlID+":TextBox1").value = currPage;
	}
	else
	{
		document.getElementById(cntrlID+"_TextBox1").value = currPage;
	}
	var str = cntrlID + ':btnNav';
	__doPostBack(str,'')
}

function setValue2(currPage,cntrlID)
{
	if (document.getElementById(cntrlID+"_TextBox1") == null)
	{
		document.getElementById(cntrlID+":TextBox1").value = currPage;
	}
	else
	{
		document.getElementById(cntrlID+"_TextBox1").value = currPage;
	}
	var str = cntrlID + ':imgNavNext';
	__doPostBack(str,'')
}

function openWin(url){ //open a pop up with a set size in top left corner
	window.open(url,'',"resizable scrollbars toolbar=no location=no");
}

function Button_Close()
{
	window.close();
}

function Button_Print()
{
	window.print();
}

function changeTab()
{
	var txtBox = document.getElementById("DeficitOrFinancing");
	if (txtBox.value == 0)
	{
		txtBox.value = 1;
	}
	else
	{
		txtBox.value = 0;
	}
}

function createFormAndSubmit(containerId,formName, formAttributes, 
inputsAttributes, submitName, clickSubmitBtn)
{
	/*********************** Insructions *****************************
	containerId -> use "" if u dont use container
	formAttributes -> attName1=attValue1$attName2=attValue2
	inputsAttributes -> input1Name=input1Value$input2Name=input2Value
	******************************************************************/
	// set the form attributes
	var frm = document.createElement('form');		
	frm.setAttribute("name",formName);
	
	var arrFormAttributes = formAttributes.split("$");
	var nameVal, i, valFormAtt;
	for(i=0; i<arrFormAttributes.length; i++)
	{
		nameVal = arrFormAttributes[i].split("=");
		valFormAtt = arrFormAttributes[i].substring(nameVal[0].length+1,arrFormAttributes[i].length)
		frm.setAttribute(nameVal[0], valFormAtt/*nameVal[1]*/);
	}

	// set the inputs attributes
	var arrInputsAttributes = inputsAttributes.split("$");
	var inputHidden;
	for(i=0; i<arrInputsAttributes.length; i++)
	{
		nameVal = arrInputsAttributes[i].split("=");
        inputHidden = document.createElement("input");		
        //inputHidden.setAttribute("name",nameVal[0]);
        inputHidden.name = nameVal[0];
		inputHidden.setAttribute("type", "hidden");
		var val1 = arrInputsAttributes[i].substring(nameVal[0].length+1,arrInputsAttributes[i].length);
		inputHidden.setAttribute("value", val1);
		frm.appendChild(inputHidden);		
	}
	
	if(clickSubmitBtn == true)
	{
	// set the submit button
	var submitBtn = document.createElement("input");
	submitBtn.setAttribute("name", submitName);
	submitBtn.setAttribute("type", "submit");
	submitBtn.setAttribute("value", "");
	frm.appendChild(submitBtn);
	}
	
	// add the form to the document
	var contId = document.getElementById(containerId);
	if(contId == null)
		{
		    document.body.appendChild(frm);
		}
	else
	    {
		    contId.appendChild(frm);
		}
	
	// submit the form
	if(clickSubmitBtn == true)
	{
	   submitBtn.click();	
	}
	else
	{
		frm.submit();
	}
		
	//alert(frm.innerHTML)
	
	// remove the form
	if (frm.parentNode)
	{
	    frm.parentNode.removeChild(frm);
	}
	
}