﻿
function Trim(sInString) 
{
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function wordCounter(field, countfield, maxlimit)
{ 
	field = document.getElementById(field);
	countfield = document.getElementById(countfield);
		
	wordcounter=0; 
	for (x=0;x<field.value.length;x++) 
	{ 
		if (field.value.charAt(x) == " " && field.value.charAt(x-1)!= " ") 
		{wordcounter++}
		if (wordcounter > 250) 
		{field.value = field.value.substring(0, x);} 
		else 
		{countfield.value = maxlimit - wordcounter;} 
	} 
} 

function textCounter(field, countfield, maxlimit) 
{ 
	field = document.getElementById(field);
	countfield = document.getElementById(countfield);
	
	if (field.value.length > maxlimit) 
	{
		field.value = field.value.substring(0, maxlimit);
	} 
	else 
	{
		countfield.value = maxlimit - field.value.length;
	} 
} 

function ChangeExternalLink()
{
	document.Frm_Menu.Link.value = document.Frm_Menu.exists.value;	
}

function GoAction(Do)
{
	if(MenuValidate()){
		
		if(Do == '1')
			document.Frm_Menu.action = 'menu.php?do=' + Do;	
		else
			document.Frm_Menu.action = '../action/menu.php';	
			
		document.Frm_Menu.submit();	
	}
}

function DeleteMenu()
{
	if(confirm("Are you sure about delete this Item?"))
	{	
		document.getElementById('do').value = "2";
		document.Frm_Menu.action = '../action/menu.php';		
		document.Frm_Menu.submit();	
	}
}

function DeleteSubMenu()
{
	//subItem
	if(document.getElementById('subId').value != ""){
		
		if(document.getElementById('subItem').value == "0"){
			if(confirm("Are you sure about delete this Item?"))
			{	
				document.getElementById('do').value = "3";
				document.Frm_Menu.action = '../action/menu.php';		
				document.Frm_Menu.submit();	
			}
		}
		else
		{
			alert('This item have sub item,can not delete!');
		}
	}
	else
	{
		alert('Please select the row!');
	}
}

function MenuValidate()
{
	Title = document.Frm_Menu.title;
	
	msg1 = 'Please insert the title!';
	
	if (Trim(Title.value) == "")
	{
		alert(msg1) ;
		Title.focus() ;
		return false ;
	}
	else
		return true;
		
}

function CheckSearch()
{
	txtSearch = document.Frmsearch.SEARCH;
	
	if(Trim(txtSearch.value) == ""){
		alert('Please enter the keyword!');
		txtSearch.focus();
		return false;	
	}	
	else
		return true;

}

function Search()
{
	  if(CheckSearch())
	  {
		document.Frmsearch.action = "search.php";
		document.Frmsearch.method = "post";
		document.Frmsearch.submit();
	 }
}

function changeColor(DIV,ch)
{
	if(ch == "1")
	document.getElementById(DIV).style.background = '#FF9900';		
	else
	document.getElementById(DIV).style.background = '#333333';
}

Width=25;

function seventeenth(){
if (window.fifteenth3)clearInterval(fifteenth3);
sixteenth3=setInterval("seventeenth3()",30);

}

function seventeenth3()
{
    var width=Home.width.split('px'); 
    width=parseInt(width[0]);
    if (document.getElementById&&width<Width)
    {
        width+=1;
		Home.width=width; 
		Contact.width=width; 
		Map.width=width; 
    }
    else if (window.sixteenth3)
        clearInterval(sixteenth3);
}

function ChangeLang(Lang)
{
	Set_Cookie( 'Lang', Lang, '','/','','');
	//window.document.location.reload(true);	
	location="index.php";
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{ 
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );

} // Set_Cookie( name, value, expires, path, domain, secure ) 

function Get_Cookie( name ) 
{
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	
	return unescape( document.cookie.substring( len, end ) );
} // Get_Cookie

// This function to slide form.
function slideForm(fromId)
{
	for(i=1;i<6;i++){
		
		divId = 'ind'+fromId;
		if(i==fromId){
			Effect.toggle(divId,'slide');
			if(document.getElementById(divId).style.display=="none"){
				document.getElementById('ind').value = fromId;
			}
			else{
				document.getElementById('ind').value = '';
			}
			
		}
		else
		{
			divId = 'ind'+i;
			if(document.getElementById(divId).style.display!="none"){
				Effect.toggle(divId,'slide');	
			}
		}
	}
	//
}

function checkIfSelectedAccount()
{
	for(i=1;i<6;i++){
		divId = 'ind'+i;
		if(document.getElementById(divId).style.display!="none"){
		     return true;
		}
	}
}

function checkIndForm()
{
	txtMail = document.getElementById('email');
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
	
			  if(Trim(document.getElementById("name1").value) == "" || 
			   Trim(document.getElementById("name2").value) == "" ||
			   Trim(document.getElementById("name3").value) == "" || 
			   Trim(document.getElementById("name4").value) == "" )
					{
							alert("Your name should be in sent in four sections");
							document.getElementById("name1").focus();
							return false;
					}
			  if(Trim(document.getElementById("address").value) == "")
					{
							alert("Kindly check the address field");
							document.getElementById("address").focus();
							return false;
					}
			  if(Trim(document.getElementById("phone").value) == "")
					{
							alert("Kindly check the phone field");
							document.getElementById("phone").focus();
							return false;
					}
		
			  if(Trim(document.getElementById("mobile").value) == "")
					{
							alert("Kindly check the mobile field");
							document.getElementById("mobile").focus();
							return false;
					}		
			  if(Trim(document.getElementById("datebirth").value) == "")
					{
								alert("Kindly check the date of birth field");
								document.getElementById("datebirth").focus();
								return false;
					}
			  if(Trim(document.getElementById("placebirth").value) == "")
					{
								alert("Kindly check the place of birth field");
								document.getElementById("placebirth").focus();
								return false;
					}
			  if(Trim(document.getElementById("nationality").value) == "")
					{
								alert("Kindly check the Nationality field");
								document.getElementById("nationality").focus();
								return false;
					}		
			  if(Trim(document.getElementById("prof").value) == "")
					{
								alert("Kindly check the Profissional field");
								document.getElementById("prof").focus();
								return false;
					}
			 if(Trim(txtMail.value) == ""){
							alert('Kindly check the e-mail!');
							txtMail.focus();
							return false;	
					}
			if(!emailpat.test( Trim(txtMail.value))){
					    	alert('Kindly enter a valid e-mail');
							txtMail.focus();
							return false;	
					}	
		
		    if(checkIfSelectedAccount()){
							 return chkFiles();
					}
			else{
				 alert("Kindly choose your Individual account type");
					return false;
				}	 
			
}	

function chkFiles()
	{

	for(i=0; i < FrmInd.elements.length; i++)
		{
			if(FrmInd.elements[i].name == "uploadfiles[]")
				{

  					if(FrmInd.elements[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display!="none")
						{
		 				if(FrmInd.elements[i].value == "")
							{
								alert("Missing Registration file");
								FrmInd.elements[i].focus();
								return false;
							}
  			 			else if(FrmInd.elements[i].value.indexOf(".")==-1)
							{
								alert("Kindly upload file");
								FrmInd.elements[i].focus();
								return false;
							}

						}
				}	
		}
	}
	
function checkCorForm()
{
	txtMail = document.getElementById('email');
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
	
			  if(Trim(document.getElementById("company").value) == "")
					{
							alert("Kindly check the company name");
							document.getElementById("company").focus();
							return false;
					}
			  if(Trim(document.getElementById("trade").value) == "")
					{
							alert("Kindly check the trade name field");
							document.getElementById("trade").focus();
							return false;
					}
			  if(Trim(document.getElementById("phone").value) == "")
					{
							alert("Kindly check the phone field");
							document.getElementById("phone").focus();
							return false;
					}
		      if(Trim(txtMail.value) == ""){
							alert('Kindly check the e-mail!');
							txtMail.focus();
							return false;	
					}
			if(!emailpat.test( Trim(txtMail.value))){
					    	alert('Kindly enter a valid e-mail');
							txtMail.focus();
							return false;	
					}
			  if(Trim(document.getElementById("address").value) == "")
					{
							alert("Kindly check the address field");
							document.getElementById("address").focus();
							return false;
					}		
			  if(Trim(document.getElementById("economic").value) == "")
					{
								alert("Kindly check the Economic sector field");
								document.getElementById("economic").focus();
								return false;
					}
			 	
		
		    if(checkIfSelectedAccount()){
							 return chkFiles();
					}
			else{
				 alert("Kindly choose your corporate account type");
					return false;
				}	 
			
}		

function filterAccount(Actions)
{
	if(Actions == '1')
		getHTML('../../grid/account.php','Value=0&pages=1&Type=1','grid')
	else if(Actions == '0')
		getHTML('../../grid/account.php','Value=0&pages=1&Type=0','grid')
		
} // this function to filter account type

function viewAccount()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
			document.Frm_grid.action = "viewaccount.php";
			document.Frm_grid.method = "post";
			document.Frm_grid.submit();
	}
	else
		alert('Please select the row!');
}

function deleteAccountView(Id)
{
	if(confirm('Are you sure about delete this account?'))
		location = 'viewaccount.php?Id='+Id;
}

function deleteAccount()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
		if(confirm('Are you sure about delete this account?')){
			document.Frm_grid.action = "account.php";
			document.Frm_grid.method = "post";
			document.Frm_grid.submit();
		}
	}
	else
		alert('Please select the row!');
	
}

function filterlocators(Actions)
{
	if(Actions == '1')
		getHTML('../../grid/locators.php','Value=0&pages=1&loc=1','grid')
	else if(Actions == '0')
		getHTML('../../grid/locators.php','Value=0&pages=1&loc=0','grid')
		
} // this function to filter account type

function filterlocatorsCity(Actions)
{
		getHTML('../../grid/locators.php','Value=0&pages=1&city='+Actions,'grid')	
}

function CheckSearchAr()
{
	txtSearch = document.Frmsearch.SEARCH;
	
	if(Trim(txtSearch.value) == ""){
		alert('!الرجاء إدخال كلمة البحث');
		txtSearch.focus();
		return false;	
	}	
	else
		return true;

}

function SearchAr()
{
	  if(CheckSearchAr())
	  {
		document.Frmsearch.action = "search.php";
		document.Frmsearch.method = "post";
		document.Frmsearch.submit();
	 }
}

function checkIndFormAr()
{
	txtMail = document.getElementById('email');
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
	
			  if(Trim(document.getElementById("name1").value) == "" || 
			   Trim(document.getElementById("name2").value) == "" ||
			   Trim(document.getElementById("name3").value) == "" || 
			   Trim(document.getElementById("name4").value) == "" )
					{
							alert("الأسم يجب أن يكون من أربع مقاطع");
							document.getElementById("name1").focus();
							return false;
					}
			  if(Trim(document.getElementById("address").value) == "")
					{
							alert("الرجاء التأكد من حقل العنوان");
							document.getElementById("address").focus();
							return false;
					}
			  if(Trim(document.getElementById("phone").value) == "")
					{
							alert("الرجاء التأكد من حقل الهاتف");
							document.getElementById("phone").focus();
							return false;
					}
		
			  if(Trim(document.getElementById("mobile").value) == "")
					{
							alert("الرجاء التأكد من حقل الهاتف   النقال");
							document.getElementById("mobile").focus();
							return false;
					}		
			  if(Trim(document.getElementById("datebirth").value) == "")
					{
								alert("الرجاء التأكد من حقل تاريخ الولاده");
								document.getElementById("datebirth").focus();
								return false;
					}
			  if(Trim(document.getElementById("placebirth").value) == "")
					{
								alert("الرجاء التأكد من حقل مكان الولاده");
								document.getElementById("placebirth").focus();
								return false;
					}
			  if(Trim(document.getElementById("nationality").value) == "")
					{
								alert("الرجاء التأكد من حقل الجنســية");
								document.getElementById("nationality").focus();
								return false;
					}		
			  if(Trim(document.getElementById("prof").value) == "")
					{
								alert("الرجاء التأكد من حقل المهنة");
								document.getElementById("prof").focus();
								return false;
					}
			 if(Trim(txtMail.value) == ""){
							alert('الرجاء التأكد من حقل البريد الألكتروني!');
							txtMail.focus();
							return false;	
					}
			if(!emailpat.test( Trim(txtMail.value))){
					    	alert('الرجاء التأكد من حقل البريد الألكتروني');
							txtMail.focus();
							return false;	
					}	
		
		    if(checkIfSelectedAccount()){
							 return chkFilesAr();
					}
			else{
				 alert("الرجاء أختيار نوع الحســاب الفردي");
					return false;
				}	 
			
}	

function chkFilesAr()
	{

	for(i=0; i < FrmInd.elements.length; i++)
		{
			if(FrmInd.elements[i].name == "uploadfiles[]")
				{

  					if(FrmInd.elements[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display!="none")
						{
		 				if(FrmInd.elements[i].value == "")
							{
								alert("الرجاء التأكد من ملفات التسجيل");
								//FrmInd.elements[i].focus();
								return false;
							}
  			 			else if(FrmInd.elements[i].value.indexOf(".")==-1)
							{
								alert("الرجاء إختيار الملف");
								//FrmInd.elements[i].focus();
								return false;
							}

						}
				}	
		}
	}
	
function checkCorFormAr()
{
	txtMail = document.getElementById('email');
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
	
			  if(Trim(document.getElementById("company").value) == "")
					{
							alert("الرجاء التأكد من حقل أســم الشــركة");
							document.getElementById("company").focus();
							return false;
					}
			  if(Trim(document.getElementById("trade").value) == "")
					{
							alert("الرجاء التأكد من حقل الأســم التجاري");
							document.getElementById("trade").focus();
							return false;
					}
			  if(Trim(document.getElementById("phone").value) == "")
					{
							alert("الرجاء التأكد من حقل الهاتف");
							document.getElementById("phone").focus();
							return false;
					}
		      if(Trim(txtMail.value) == ""){
							alert('الرجاء التأكد من حقل البريد الألكتروني');
							txtMail.focus();
							return false;	
					}
			if(!emailpat.test( Trim(txtMail.value))){
					    	alert('الرجاء التأكد من حقل البريد الألكتروني');
							txtMail.focus();
							return false;	
					}
			  if(Trim(document.getElementById("address").value) == "")
					{
							alert("الرجاء التأكد من حقل العنوان");
							document.getElementById("address").focus();
							return false;
					}		
			  if(Trim(document.getElementById("economic").value) == "")
					{
								alert("الرجاء التأكد من حقل القطاع الاقتصادي");
								document.getElementById("economic").focus();
								return false;
					}
			 	
		
		    if(checkIfSelectedAccount()){
							 return chkFiles();
					}
			else{
				 alert("الرجاء أختيار نوع حســاب الشــركات");
					return false;
				}	 
			
}			

function popUp(URL,WinWidth,WinHeight) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + WinWidth + ",height=" + WinHeight + ",left = 312,top = 234');");
}

function filterContact(Actions)
{
		getHTML('../../grid/contact.php','Value=0&pages=1&st='+Actions,'grid');
		
} // this function to filter account type

function filterJob(Actions)
{
		getHTML('../../grid/apply.php','Value=0&pages=1&st='+Actions,'grid');
		
} // this function to filter account type

//Lang = Get_Cookie('Lang');
//Set_Cookie( 'Lang', '1', '','/','','');