﻿function OpenWindowNoToolbars(url,height,width)
{
	window.open(url,'',"height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no");
}

function PrintOnLoad()
{
     window.print();	
}

function ResetMyForm()
{
    var theForm = document.forms['aspnetForm'];
if (!theForm) 
    theForm = document.aspnetForm;
	theForm.clear();
}
function ResetTdsClass(table)
 {

   var cells=table.getElementsByTagName("td");

    for (var i = 0; i < cells.length; i++)
    { 
        cells[i].className=""; 
    }

 }

var show_login_error=true;

function StudLogin(client_id,url,no_user_msg,no_password_msg)
{
	try
	{
		var username_id=client_id+'_username';
		var username_inp=document.getElementById(username_id);
		

		if(username_inp==null || Trim(username_inp.value)=='')
		{
			alert(no_user_msg);
			return;
		}
		else
		    username_inp.name="username";
		
		var password_id=client_id+'_password';
		var password_inp=document.getElementById(password_id);
		if(password_inp==null || Trim(password_inp.value)=='')
		{
			alert(no_password_msg);
			return;
		}
		else
		    password_inp.name="password";

		var curl_inp=document.getElementById(client_id+'_curl');
		if(curl_inp!=null)
		{
			curl_inp.name="curl";
			
		}
		else
		{
			if(show_login_error)
				alert("curl missing");
			return;
		}

		var flags_inp=document.getElementById(client_id+'_flags');
		if(flags_inp!=null)
		{
			flags_inp.name="flags";
			
		}
		else
		{
			if(show_login_error)
				alert("flags missing");
			return;
		}
		
		var forcedownlevel_inp=document.getElementById(client_id+'_forcedownlevel');
		if(forcedownlevel_inp!=null)
		{
			forcedownlevel_inp.name="forcedownlevel";
			
		}
		else
		{
			if(show_login_error)
				alert("forcedownlevel missing");
			return;
		}

		var formdir_inp=document.getElementById(client_id+'_formdir');
		if(formdir_inp!=null)
		{
			formdir_inp.name="formdir";
			
		}
		else
		{
			if(show_login_error)
				alert("formdir missing");
			return;
		}

		/*var username_inp=document.getElementById(client_id+'_username');
		if(username_inp!=null)
		{
			username_inp.name="username";
			
		}

		var password_inp=document.getElementById(client_id+'_password');
		if(password_inp!=null)
		{
			password_inp.name="password";
			
		}*/


		var SubmitCreds_inp=document.getElementById(client_id+'_SubmitCreds');
		if(SubmitCreds_inp!=null)
		{
			SubmitCreds_inp.name="SubmitCreds";
			
		}
		else
		{
			if(show_login_error)
				alert("SubmitCreds missing");
			return;
		}

		var theform = document.forms[0];
		theform.action=url;
		if(document.all)
		{
		if(document.all('__VIEWSTATE')!=null)
			document.all('__VIEWSTATE').outerHTML="";
		if(document.all('__EVENTARGUMENT')!=null)
			document.all('__EVENTARGUMENT').outerHTML="";
		if(document.all('__EVENTTARGET')!=null)    
			document.all('__EVENTTARGET').outerHTML="";	
		
		}
		theform.submit();
	}
	catch(e)
	{
		alert(e.message);
	}
}


function Go2Results(results_path,search_input_id,no_input_msg,params)
{

	var search_input=document.getElementById(search_input_id);
	if(search_input==null)
	{
		alert('error');
		return;
	}
	
	if(Trim(search_input.value)=='' )
	{
		alert(no_input_msg);
		return;
	}

	var path=results_path; 
	
	if(Trim(search_input.value)!='')
		path+='&k='+MycanonicalizedUtf8FromUnicode(Trim(search_input.value));
	
	
	if(Trim(params)!='')
		path+=Trim(params);
	
	path=path.replace('&','?');
	location.href=path;
}

if (document.addEventListener){
        document.addEventListener('keydown', checkMyKey, false);
      }
      else if (document.attachEvent)
      {
      document.attachEvent('onkeydown', checkMyKey);
      }

 function checkMyKey(e)
        {
       
            if (!e) var e = window.event;

            if (e.keyCode)
            { code = e.keyCode; }
            else if (e.which)
            { code = e.which; }
            
            if (code == 13  )
            {

               var SrcElement=null;
		            if(document.all)
		                SrcElement=e.srcElement;
		            else 
		                SrcElement=e.target;
		                 
                if(SrcElement !=null && SrcElement.id !=null && (SrcElement.id=='ctl00_PlaceHolderMain_search_tb' || SrcElement.id=='ctl00_search_tb'))	
		        {
		        
		       //alert(SrcElement);

		        if(document.all)
			            SrcElement.blur();
        		  var tbl=SrcElement.parentNode.parentNode.parentNode.parentNode; //row
        		 
        		  var td2=tbl.rows[0].cells[2];
        		  
        		  var sBtn  = td2.firstChild;

			  
        		  if(sBtn!=null)
		            sBtn.click();   
        		  return false;
                		
		        }
		 
            }
        
       
        
        }

/**************/
function Trim(TRIM_VALUE){
if(TRIM_VALUE==null || TRIM_VALUE==undefined)
	return"";
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

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;

} //End While
return strTemp;

} //End Function

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;
} //End While
return strTemp;
} //End Function

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){
	var c = s.charAt(i);
	if (((c < '0') || (c > '9'))) return false;
	}
	return true;
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = '';
	for (i = 0; i < s.length; i++){
	var c = s.charAt(i);
	if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

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 MycanonicalizedUtf8FromUnicode(strURL) 
{
var my_i7F = parseInt("0x7F");
var my_i7FF = parseInt("0x7FF");
var my_iFFFF = parseInt("0xFFFF");
var my_i1FFFFF = parseInt("0x1FFFFF");
var my_i3FFFFFF = parseInt("0x3FFFFFF");
var my_i7FFFFFFF = parseInt("0x7FFFFFFF");
    var strSpecialUrl = " <>\"#%{}|^~[]`&?+";
    var strEncode="";
    var i;
    var chUrl;
    var iCode;
    var num;
    var iCodeBin;
    var tempBin;
    var j, leadingzeros;

    strURL += "";
    for (i=0; i<strURL.length; i++) {
        chUrl = strURL.charAt(i);
        iCode = chUrl.charCodeAt(0);
        if (iCode<=my_i7F)
        {
            if (strSpecialUrl.indexOf(chUrl)!=-1)
            {

                strEncode+="%"+iCode.toString(16).toUpperCase();
            }
            else
            {

                strEncode+=chUrl;
            }
        }
        else
        {
            leadingzeros="";
            iCodeBin=iCode.toString(2)
            if (iCode<=my_i7FF)
            {

                for (j=11; j>iCodeBin.length; j--) leadingzeros+="0";
                iCodeBin=leadingzeros+iCodeBin

                tempBin="110"+iCodeBin.substr(0,5);
                strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                tempBin="10"+iCodeBin.substr(5,6);
                strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
            }
            else
            {
                if (iCode<=iFFFF)
                {

                    for (j=16; j>iCodeBin.length; j--) leadingzeros+="0";
                    iCodeBin=leadingzeros+iCodeBin

                    tempBin="1110"+iCodeBin.substr(0,4);
                    strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                    tempBin="10"+iCodeBin.substr(4,6);
                    strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                    tempBin="10"+iCodeBin.substr(10,6);
                    strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                }
                else
                {
                    if (iCode<=my_i1FFFFF)
                    {

                        for (j=21; j>iCodeBin.length; j--) leadingzeros+="0";
                        iCodeBin=leadingzeros+iCodeBin

                        tempBin="11110"+iCodeBin.substr(0,3);
                        strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                        tempBin="10"+iCodeBin.substr(3,6);
                        strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                        tempBin="10"+iCodeBin.substr(9,6);
                        strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                        tempBin="10"+iCodeBin.substr(15,6);
                        strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                    }
                    else
                    {
                        if (iCode<=my_i3FFFFFF)
                        {

                            for (j=26; j>iCodeBin.length; j--) leadingzeros+="0";
                            iCodeBin=leadingzeros+iCodeBin

                            tempBin="111110"+iCodeBin.substr(0,2);
                            strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                            tempBin="10"+iCodeBin.substr(2,6);
                            strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                            tempBin="10"+iCodeBin.substr(8,6);
                            strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                            tempBin="10"+iCodeBin.substr(14,6);
                            strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                            tempBin="10"+iCodeBin.substr(20,6);
                            strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                        }
                        else
                        {
                            if (iCode<=my_i7FFFFFFF)
                            {

                                for (j=31; j>iCodeBin.length; j--) leadingzeros+="0";
                                iCodeBin=leadingzeros+iCodeBin

                                tempBin="1111110"+iCodeBin.substr(0,1);
                                strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                                tempBin="10"+iCodeBin.substr(1,6);
                                strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                                tempBin="10"+iCodeBin.substr(7,6);
                                strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                                tempBin="10"+iCodeBin.substr(13,6);
                                strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                                tempBin="10"+iCodeBin.substr(19,6);
                                strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                                tempBin="10"+iCodeBin.substr(25,6);
                                strEncode+="%"+parseInt(tempBin,2).toString(16).toUpperCase()
                            }
                        }
                    }   
                }           
            }
        }
    }
    return strEncode;
}


/****************/


function GetPageName(strPageId, txtClientId, btnClientId, linkId)
{

    if(strPageId != "" && strPageId != null)
    {
        if(txtClientId != null && txtClientId != "")
        {
            document.getElementById(txtClientId).value = strPageId;
        }
        
        if(btnClientId != null && btnClientId != "")
        {
            document.getElementById(btnClientId).click();
        }
    }
    
    document.getElementById(linkId).style.className = 'a-navigation-click';
}


function SendLidForm(fName, lName, areaCode, phone, email, subject, yesMore, noMore, clientId)
{
    
    try
    {
        var val;
           
        if(fName != null )
        {
            val = document.getElementById(fName).value;
            
            if(val == null || val == '')
            {
                alert('נא למלא את כל השדות');
                return false;
            }
            
              if(IsInvalidName(val))
            {
                alert('שם פרטי לא חוקי');
                return false;
            }
            
            document.getElementById(clientId + "Fname").value = val;
        }
        
        if(lName != null)
        {
            val = document.getElementById(lName).value;
            
            if(val == null || val == '')
            {
                alert('נא למלא את כל השדות');
                return false;
            }
             if(IsInvalidName(val))
            {
                alert('שם משפחה לא חוקי');
                return false;
            }
            document.getElementById(clientId + "Lname").value = val;
        }
        
        if(areaCode != null)
        {
            var areaCode_list= document.getElementById(areaCode);
           
            if(areaCode_list.value!='-1')
                document.getElementById(clientId + "AreaCode").value = areaCode_list.options[areaCode_list.selectedIndex].text;
            else
            {
                 alert('נא למלא את כל השדות');
                 return false;
            }
        }
            
        if(phone != null)
        {
            val = document.getElementById(phone).value;
            
            if(val == null || val == '')
            {
                alert('נא למלא את כל השדות');
                return false;
            }
            else
                {
                    if(CheckPhone(val) == false)
                    {
                        alert('מספר הטלפון שהוכנס אינו תקין');
                        return false;
                    }
                }
            document.getElementById(clientId + "Phone").value = val;
        }
         
        document.getElementById(clientId + "Phone").value = document.getElementById(clientId + "AreaCode").value + "-" + document.getElementById(phone).value;
         
        if(email != null)
        {
            val = document.getElementById(email).value;
            
            if(val == null || val == '')
            {
                alert('נא למלא את כל השדות');
                return false;
            }
            
			
			if(!CheckEmail(val))
			{
			    alert("שדה דוא''ל אינו חוקי");
			    return false;
			}
			
            document.getElementById(clientId + "Email").value = val;
        }
           
           
         if(yesMore != null && noMore != null)
        {
            var yesValue = document.getElementById(yesMore).checked;
            var NoValue = document.getElementById(noMore).checked;
                       
            if(yesValue == false && NoValue == false)
            {
                alert('נא למלא את כל השדות');
                return false;
            }
             if(yesValue)
            {
                val="כן";
            }
            else if(NoValue)
            {
                val = "לא";
            }                     
            document.getElementById(clientId + "approveMail").value = val;                      
        }
         
       
        if(subject != null)
        {
           var subject_list= document.getElementById(subject);

           if(subject_list.value!='0')
            {    document.getElementById(clientId + "Subject").value = subject_list.options[subject_list.selectedIndex].value;
}
           else 
           {
                alert('נא למלא את כל השדות');
                return false;
           }
        }
     
        try
        {
              	var theform = document.forms[0];
              	
		       //theform.action='http://www.mccanndigital.co.il/ManagementCollege/formColmanNewSite.asp'; 
			theform.action='http://media.colman.ac.il/formColmanNewSite.asp'; //my_form.action;

		        if(document.all)
		        {
		        if(document.all('__VIEWSTATE')!=null)
			        document.all('__VIEWSTATE').outerHTML="";
		        if(document.all('__EVENTARGUMENT')!=null)
			        document.all('__EVENTARGUMENT').outerHTML="";
		        if(document.all('__EVENTTARGET')!=null)    
			        document.all('__EVENTTARGET').outerHTML="";	
        		
		        }
		        if(document.getElementById(clientId + "M2CID") !=  null)
		            document.getElementById(clientId + "M2CID").name = "M2CID";
		           
		       if(document.getElementById(clientId + "site") !=  null)
		            document.getElementById(clientId + "site").name = "site";
		            
		       if(document.getElementById(clientId + "ReturnTo") !=  null)
		            document.getElementById(clientId + "ReturnTo").name = "ReturnTo";

			 if(document.getElementById(clientId + "Fname") !=  null)
		            document.getElementById(clientId + "Fname").name = "Fname";

			 if(document.getElementById(clientId + "Lname") !=  null)
		            document.getElementById(clientId + "Lname").name = "Lname";

			 if(document.getElementById(clientId + "Phone") !=  null)
		            document.getElementById(clientId + "Phone").name = "Phone"; 

			if(document.getElementById(clientId + "AreaCode") !=  null)
		            document.getElementById(clientId + "AreaCode").name = "AreaCode"; 

			if(document.getElementById(clientId + "Email") !=  null)
		            document.getElementById(clientId + "Email").name = "Email";

			if(document.getElementById(clientId + "Subject") !=  null)
		            document.getElementById(clientId + "Subject").name = "OptionID";
		            
		    if(document.getElementById(clientId + "approveMail") !=  null)
		            document.getElementById(clientId + "approveMail").name = "approveMail";
		     			     
		     theform.submit();
		     alert('הטופס נשלח בהצלחה');
        }
        catch (e)
        {
            alert(e.message);
            return false;
        }
       
    
    }
    catch(e)
    {
        alert(e.message);
        return false;
    }
    return false;
}



function check(elem)
{
    try
    {
    if(document.getElementById(elem).value == '')
	    {
		    alert('נא למלא את כל השדות');
		    return false;
	    }	   
     }
     catch(e)
     {
     alert(e.message);
     return false;
     }
    return true;
}


function ClearForm (fName, lName, areaCode, phone, email, subject, yesMore, noMore)
{
    try
    {
    
        if(lName != null)
        {
            document.getElementById(lName).value = "";
        }
        
          
        if(fName != null )
        {
           document.getElementById(fName).value = "";
        }
        
        if(areaCode != null)
        {
            var areaCode_list= document.getElementById(areaCode);
           areaCode_list.value='-1';
        }
            
        if(phone != null)
        {
            document.getElementById(phone).value = "";
        }
         
        if(email != null)
        {
            document.getElementById(email).value = "";
        }
           
        if(subject != null)
        {
           var subject_list= document.getElementById(subject);
           subject_list.value='0';
        }
      
        if(yesMore != null)
        {
           document.getElementById(yesMore).checked = false;
        }
        
        if(noMore != null)
        {
           document.getElementById(noMore).checked = false;
        }
    }
    catch(e)
    {
        alert(e.message);
        return false;
    }
    
    return false;
}


function CheckPhone(sText)
{
    var ValidChars = '0123456789';
    var IsNumber=true;
    var Char;
    
    if(sText.length == 7)
    {
        for (i = 0; i < sText.length && IsNumber == true; i++)
        {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1)
            {
             IsNumber = false;
            }
        }
        return IsNumber;
    }
    else
    {        
        return false;
    }
}


function CheckEmail(sText)
{
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
    
    if (!filter.test(sText))
    {
        return false;
    }
    else
    {
        return true;
    }
}

function CheckIsAlphabet(sText)
{
    var filter=/^[a-zA-Z. \u0621-\u064A]{1,50}$/;
    
    if (!filter.test(sText))
    {
        return false;
    }
    else
    {
        return true;
    }
}

function IsInvalidName(sText)
{

var InValidChars = "0123456789<>?/).,_-(*&^%$#@!~`;+=\"";
var IsInValid=false;
var Char;

if (sText.length > 50)
return true;
// IsValidID = true;
for (i = 0; i < sText.length && IsInValid == false; i++) 
{ 
Char = sText.charAt(i); 
if (InValidChars.indexOf(Char) >= 0) 
{
IsInValid = true;
}
}
return IsInValid;
}


