// Form Validator
var supportcenter_login_box="";
var toggle_menu_html;
function $(id){	
    var obj = null;
	if(document.getElementById){obj = document.getElementById(id);}
	else if(document.all){obj = document.all[id];}
    return obj;
}
function regCheckItem(itemType) {
	var fullname	= $('news_fullname').value;// myForm.fullname.value;
	var	email		= document.getElementById('news_email').value; // myForm.email.value.toLowerCase();
	if(itemType.indexOf('name')>-1){
		checkFullname(fullname);
	}
	else if(itemType.indexOf("mail")>-1){
		checkEmail(email);
	}
}

function checkForm() {
	var fullname	= $("news_fullname").value;
	var	email		= $("news_email").value.toLowerCase();
	if(checkFullname(fullname) && checkEmail(email)){
		$("result_uptodate_user").style.display="block";
		sR("/beta/uptodate_user.php","name="+fullname+"&email="+email,"POST","result_uptodate_user");
		return true;
	}
	else return false;
}

function checkFullname(fullname){
	if(notEmpty(fullname)) {
		var msg = 'OK';
		changeDiv('fullname_check','reg_white',msg);
		return true;	
	}
	else {
		var msg = 'Error';
		changeDiv('fullname_check','reg_red',msg);
		return false;
	}
}
function checkEmail(email){
	if(isMail(email)) {
		var msg = 'OK';
		changeDiv('email_check','reg_white',msg);
		return true;
	}
	else {
		var msg = 'Error';
		changeDiv('email_check','reg_red',msg);
		return false;
	}
}

function checkEmailInc(email){
	if((isMail(email))&&(email==$('confirm_email').value)) {
		return true;
	}
	else if(email=="") {
		alert('E-mail is a required field')
		return false;
	}
	else if($('confirm_email').value=='') {
		alert('Confirm email is a required field')
		return false;
	}
	else if(email!=$('confirm_email').value) {
		alert('E-mail is not match the confirmation')
		return false;
	}
	
	else {
		alert('Wrong email format')
		return false;
	}
}
function checkEmailInc2(email){
	if((isMail(email))&&($('first').value!="")&&($('last').value!="")&&($('phone').value!="")) {
		return true;
	}
	else if(email=="") {
		alert('E-mail is a required field')
		return false;
	}
	else if($('first').value=="") {
		alert('First name is a required field')
		return false;
	}
	else if($('last').value=="") {
		alert('Last name is a required field')
		return false;
	}
	else if($('phone').value=="") {
		alert('Phone no. is a required field')
		return false;
	}
	else {
		alert('Wrong email format')
		return false;
	}
}

/////////////////////////////////////////////////////////////////
function notEmpty(elem){
	var filter=(/^[a-zA-Z0-9]+$/);
	if (filter.test(elem) && elem.length >= 3) return true;
	else return false;
}
function isMail(elem) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(elem))return true;
	else return false;
}


function changeDiv(divId,class_name,msg) {
	document.getElementById(divId).className=class_name;
	document.getElementById(divId).innerHTML=msg;
}


function set(type1,ITEMHERE){
	if(type1=="good"){
			$(ITEMHERE).style.backgroundColor="#EEFFEE";
			$(ITEMHERE).style.borderLeft="#33BB66 5px solid";			
	}else{
			$(ITEMHERE).style.backgroundColor="#FFEEEE";		
			$(ITEMHERE).style.borderLeft="#FF9999 5px solid";											
	}
}
function matchit(item1,in_item2) {
  var re = new RegExp(item1);
  var m = re.exec(in_item2);
  if (m == null) return false;
  else return (m.index+1);
}
function isNumber(elem){
	var filter=(/^[0-9]+$/);
	if (filter.test(elem) && elem.length >= 7) return true;
	else return false;
}
var check_name=false , check_email=false , check_project=false ,check_no=false;
var bad="<img src='images/invalid.gif' border='0' alt='Error' align='absmiddle' /> ";
var good="<img src='images/validate.gif' border='0' alt='Valid' align='absmiddle' /> ";	
function send_mail(){
	var myForm		= window.document.requestforquote_form;
	var fullname	= myForm.requestforquote_form_name.value;
	var	email		= myForm.requestforquote_form_email.value.toLowerCase();
	var phone   	= myForm.requestforquote_form_phone.value;
	var project		= myForm.requestforquote_form_message.value;
	var company		= myForm.requestforquote_form_company.value;
	var contact		= myForm.requestforquote_form_addinfo.value;
	sR("login.php?op=send_email&fullname="+fullname+"&email="+email+"&phone="+phone+"&co="+company+"&project="+project+"&contact="+contact,"","POST","result_send");
	return false; 
}
function $(id){  
	var obj = null;
	if(document.getElementById){   
		obj = document.getElementById(id);
    }
	else if(document.all)
	{ obj = document.all[id]; }; 
	return obj; 
}
function portfolio_hover_on(div_id){
	$(div_id).style.background = '#DEDEDE';
}
function portfolio_hover_off(div_id){
	$(div_id).style.background = '#F5F5F5';
}
function sc_hover_on(div_id){
	$(div_id).style.background = '#F4F4F4';
	$(div_id).style.border = '1px solid #CCCCCC';
}
function sc_hover_off(div_id){
	$(div_id).style.background = '#FFFFFF';
	$(div_id).style.border = '1px solid #EEEEEE';
}

function alertSize() {
    if (self.innerWidth) {   // FirFox
      myWidth = self.innerWidth;
      myHeight = self.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { // IE
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
	  myWidth=myWidth+21;
    } else if (document.body) {
      myWidth = document.body.clientWidth;
      myHeight = document.body.clientHeight;
    }
	return myWidth;
}
function set_toggle_image()	{
	var obj_toggle_menu=$('toggle_menu');
	var submit_image=$('toggle_submit_image');
	submit_image.style.top=323+"px";
	submit_image.style.left=alertSize()-50+"px";
	submit_image.style.right=32+"px";
	submit_image.style.width=0+"px";
}

var z=new Array();
var thespeed=10;
var intervalID;
var obj_here;
function hide_now(obj_here)
{
	x=$(obj_here);
	ht=x.offsetHeight;
	thespeed=parseInt(parseInt(ht)/20)+1;
	$(obj_here).style.height=parseInt(ht)+"px";
	intervalID=setInterval("decrease('"+obj_here+"')",20);
	//decrease(obj_here);
}
function hide_now_send(obj_here,target)
{
	x=$(obj_here);
	ht=x.offsetHeight;
	thespeed=5;
	intervalID=setInterval("decrease_send('"+obj_here+"','"+target+"')",20);
	//decrease(obj_here);
}

function show_now(obj_here,extra)
{
	if(!extra)extra=0;
	x=$(obj_here);
	x.style.display="block";	
	x.style.overflow="visible";		
	x.style.height="";
	ht=x.offsetHeight;
	thespeed=parseInt(parseInt(ht)/20)+1;
	x.style.overflow="hidden";
	x.style.height="0px";
	x.style.display="block";
	intervalID=setInterval("increase('"+obj_here+"','"+ht+"')",30);
	//increase(ht,obj_here,z.length,extra);
}
function Toggle_contact(OBJECT)
{	
	if($("toggle_send"))$("toggle_send").style.display="none";
	var obj=document.getElementById(OBJECT);
	if (obj.style.display!="none" || obj.style.display=="block")
	{
		hide_now(OBJECT);
	}
	else
	{
		reset_toggle_objects();
		set_toggle_image();
		show_now(OBJECT);
	}
}
function increase(obj_here,hx){
	IndexOFz=0;
	var btn_getQuote=$('btn_getQuote');
	var x=$(obj_here);
	x.style.overflow='hidden';
	ht=x.style.height;
	x.style.height=(parseInt(x.style.height)+thespeed)+"px";	
	
	if(parseInt(x.style.height)>0)
	x.style.height="0px";						
	if (parseInt(ht)<(parseInt(hx)-(thespeed-1))) 
	{
		ht=parseInt(ht)+thespeed;
		x.style.height=parseInt(ht)+"px";
		//z[IndexOFz]=setTimeout("increase("+hx+",'"+obj_here+"',"+IndexOFz+","+extraOPTION+")",30);
	}
	else {
		x.style.height="";
		x.style.overflow='visible';
		clearInterval(intervalID);
		//clearTimeout(z[IndexOFz]);	
		x.style.visibility='visible';		
		image_move();
	}
}
function decrease(obj_here,IndexOFz,extraOPTION){
	if(!extraOPTION)extraOPTION=0;
	var submit_image=$('toggle_submit_image');
	var btn_getQuote=$('btn_getQuote');	
	x.style.overflow='hidden';
	x=$(obj_here);
	ht=parseInt(x.style.height);
	x.style.zIndex=-20;
	if (ht>(thespeed-1)) 
	{
		ht=ht-thespeed;
		if(extraOPTION==1){
			x.style.top=(parseInt(x.style.top)+thespeed)+"px";
		}
		x.style.height=ht+"px";
		if(x.style.height=="")x.style.height="0";
		x.style.height=Math.abs((parseInt(x.style.height)-thespeed))+"px";				
		if(!IndexOFz){
			var IndexOFz=z.length;
		}
		if(parseInt(submit_image.style.width)>20)submit_image.style.width=Math.abs(parseInt(submit_image.style.width)-20)+"px";
		else submit_image.style.width=0+"px";
		submit_image.style.left=parseInt(submit_image.style.left)+18+"px";
		//z[IndexOFz]=setTimeout("decrease('"+obj_here+"',"+IndexOFz+","+extraOPTION+")",30);
	}
	else{
		x.style.height=0+"px";
		x.style.display="none";
		clearInterval(intervalID);
		//clearTimeout(z[IndexOFz]);	
	}
}
function decrease_send(obj_here,target){
	target=parseInt(target);
	x.style.overflow='hidden';
	x=$(obj_here);
	ht=parseInt(x.style.height);
	if (ht>(thespeed+target)) 
	{
		x.style.height=ht+"px";
		if(x.style.height=="")x.style.height="0";
		x.style.height=Math.abs((parseInt(x.style.height)-thespeed))+"px";				
		//z[IndexOFz]=setTimeout("decrease('"+obj_here+"',"+IndexOFz+","+extraOPTION+")",30);
	}
	else{
		x.style.height=target+"px";
		//clearTimeout(z[IndexOFz]);
		if(target!=0){
			$("toggle_send").innerHTML="... Sending Data ...<br />PLeae Wait";
			
			sR("http://www.linkegypt.com/send_contact_us.php","name="+name+"&email="+email+"&phone="+phone+"&company="+
		   	company+"&project="+project+"&code="+code+"&contacted="+contacted,"POST","toggle_send");
			
		}
		clearTimeout(intervalID);
	}
}
var IndexOFz=0;
function image_move()
{
	/*IndexOFz=0;
	var submit_image=$('toggle_submit_image');
	submit_image.style.display="block";
	if(parseInt(submit_image.style.width)<151){
		submit_image.style.width=parseInt(submit_image.style.width)+10+"px";
		submit_image.style.left=parseInt(submit_image.style.left)-10+"px";
		z[IndexOFz]=setTimeout("image_move()",30);
	}
	else{
		clearTimeout(z[IndexOFz]);
		//prompt('',$("toggle_menu").innerHTML);
	}*/
}
var total_details=1;
var old_cutter;
function add_detail(object_id,str_cutter){
	if(old_cutter!=str_cutter)total_details=1;
	var dt_tbl=$(object_id).tBodies[0];
	var copy_cell=dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[0].innerHTML;	
	var copy_cell2=dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[1].innerHTML;
	//alert(copy_cell2);
	while(copy_cell.indexOf(str_cutter+total_details)>-1)
	copy_cell=copy_cell.replace(str_cutter+total_details,str_cutter+parseInt(total_details+1));
	total_details++;
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[1].innerHTML="";
	dt_tbl.insertRow(dt_tbl.rows.length);
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].insertCell(0);
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].insertCell(1);
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[0].innerHTML=copy_cell;
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[1].style.verticalAlign="bottom";
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[1].innerHTML=copy_cell2;
	old_cutter=str_cutter;
}
function customize_display(){
	$('rightcolumn_middle_page').style.visibility="hidden";
	$('topsection_page').style.display="none";
	$('contentcolumn_page_left').style.marginRight=230+"px";
}
function screencast_with(){
	
	if($("job_form") ||  $("applied_cv_successfully") || $("career_registered_email") || $("wrong_image_word")){
		customize_display();
		initiate_validation_career('job_form');
	}
	if($("applied_cv_successfully")){
		$('career_top_submit').style.visibility="hidden";
		$('topsection_page').style.display="none";
		$('link_egypt_int_body_padding').innerHTML=
		'<div style="text-align:center;font-size:14px;font-weight:bold;color:#666666;font-family:Georgia">'
		+'<br />You are applied successfully ...<br />'
		+'<span style="font-size:12px;font-weight:normal;">you will be redirect to the Home page</span></div>';
		setTimeout("window.location='index.html'", 3000 );
	}
	if($("applied_Links_successfully")){
		$('career_top_submit').style.visibility="hidden";
		customize_display();
		setTimeout("window.location='index.html'", 3000 );
	}
	if($("career_registered_email")){
		$('career_top_submit').style.visibility="hidden";
		$('topsection_page').style.display="none";
		$('link_egypt_int_body_padding').innerHTML=
		'<div style="font-size:14px;text-align:center;font-weight:bold;color:#666666;font-family:Georgia">'
		+'<br />The e-mail address that you entered is already submitted before.'
		+'<br /><span style="font-size:12px;font-weight:normal;">you will be redirect to the Careers page</span></div>';
		setTimeout("history.go(-1)", 3000 );
	}
	if($("wrong_image_word")){
		$('career_top_submit').style.visibility="hidden";
		$('topsection_page').style.display="none";
		$('link_egypt_int_body_padding').innerHTML=
		'<div style="font-size:14px;text-align:center;font-weight:bold;color:#666666;font-family:Georgia">'
		+'<br />Wrong Inputs for "Characters in Images"...<br /> '
		+'<span style="font-size:12px;font-weight:normal;">you will be redirect to the Careers page</span></div>';	
		setTimeout("history.go(-1)", 3000 );
	}
	if($("links_registered_url") || $("wrong_link_image_word")){
		$('career_top_submit').style.visibility="hidden";
		customize_display();
		setTimeout("history.go(-1)", 3000 );
	}
		
	if($("see_also_related"))$("see_also_related").style.width=parseInt(alertSize())-700+"px";
	if($("other_screen_block"))$("other_screen_block").style.width=parseInt(alertSize())-700+"px";
	if($("screen_block"))$("screen_block").style.width=parseInt(alertSize())-700+"px";
	if($("tag_cloud_block"))$("tag_cloud_block").style.width=parseInt(alertSize())-700+"px";
	if($("right_block_col"))$("right_block_col").style.width=parseInt(alertSize())-675+"px";
	if($("header_top_text"))$("header_top_text").style.marginRight=0+"px";
}

function toggle_onfocus(id){
	$(id).style.color='#DDDDDD';
	$(id).style.borderColor='#FFFFFF';
	$(id).style.background='#999999';
}
function toggle_onblur(id){
	$(id).style.color='#666666';
	$(id).style.borderColor='#999999';
}
function toggle_onfocus_r(id){
	$(id).style.color='#DDDDDD';
	$(id).style.borderColor='#FFFFFF';
	$(id).style.background='#999999';
}
function toggle_onblur_r(id){
	$(id).style.color='#666666';
	$(id).style.borderColor='#999999';
	$(id).style.background='#DDDDDD';
}
var name
var email
var phone
var company
var project
var code
var contacted
function start_send()
{	
	if(validate_all())
	{
		name=$("toggle_name").value;
		email=$("toggle_email").value;
		phone=$("toggle_phone").value;
		company=$("toggle_company").value;
		project=$("toggle_project").value;
		code=$("CODE").value;
		contacted=$("toggle_contacted").value;
		$("toggle_send").style.display="block";
		
		$("toggle_menu").style.display="none";
		$("toggle_send").style.height="210px";
		hide_now_send("toggle_send",105);
	}
}
function reset_toggle_objects()
{
	reset_item("toggle_name");
	reset_item("toggle_email");
	reset_item("toggle_phone");
	reset_item("toggle_company");
	reset_item("toggle_project");
	reset_item("CODE");
	reset_item("toggle_contacted");	
}
function applied_cv(){
	$("link_egypt_int_body_padding").innerHTML="<div class='added_cv'>You are applied successfully ...</div>";
}
function reset_item(item_id)
{
	$(item_id).value="";
	$(item_id).style.color="#444444";
	$(item_id).style.background="#999999";
	$(item_id).style.border="solid ";
	$(item_id).style.borderWidth="1px";
	$(item_id).style.borderColor="#CCCCCC";
	if($(item_id+'_validation'))$(item_id+'_validation').style.display="none";
}
function showdiv(id)
{
	var div_tocopy=$(id+'_con');
	var targetdiv=$('target');
	targetdiv.innerHTML=div_tocopy.innerHTML;
}
function hide_submenu(){
	$("topsection_page").style.display="none";
}
function validate_all_career(form_type){
	bad="<span style='color:#F68720;'>Invalid</span>";
	if(form_type=="career"){
	validation_array=Array("name_info","last_name_info","city_info","email_info","zip_code_info","home_phone_info","work_phone_info","cell_phone_info","image_verfication");
	get_id('job_form').action="career.html";
	}
	else if(form_type="link_exchange"){
		validation_array=Array("website_url","website_title","name","email","image_verfication");
		get_id('job_form').action="link_exchange.html";
	}
	for(var L=0;L<validation_array.length;L++){
		validate_item_career(validation_array[L]);
	}
if(get_id("job_form_container").innerHTML.indexOf("Invalid")>-1 || get_id("job_form_container").innerHTML.indexOf("Invalid")>-1){
		return false;	
	}else{
		get_id('job_form').submit();
		return true;	
	}
}
function validate_item_career(itemID){
	var msg="";
	var finalID=itemID+"_validation";
	get_id(finalID).style.alignText="left";
	get_id(finalID).style.display="block";
	switch(itemID){//("first_name_info","last_name_info","last_name_info","email_info","zip_code_info","home_phone_info","work_phone_info","cell_phone_info","image_verfication")
		case "name_info": case "last_name_info": case "last_name_info": case "city_info": case "website_url": case "website_title": case "name": case "email":
		if(get_id(itemID).value.length==0){
			msg=bad;
		}else{
			msg=good;
		}
		break;
		case "email_info":
			if(matchit("[0-9]",get_id(itemID).value)==1){
				msg=bad;
			}		
			else if(check_email(get_id(itemID).value)==false){
				msg=bad;
			}
			else{
				msg=good;
			}	
		break;
		case "zip_code_info": case "home_phone_info": case "work_phone_info": case "cell_phone_info":
			if(get_id(itemID).value.toString()!=parseInt(get_id(itemID).value.toString())){
				msg=bad;
			}		
			else{
				msg=good;			
			}	
		break;
		case "image_verfication":
			if(get_id(itemID).value.length!=5){
				msg=bad;
			}
			else{
				msg=good;
			}
		break;

	}
	if(msg.indexOf(bad)>-1){
		get_id(itemID).style.background='#F4E9E6';
	}else{
		get_id(itemID).style.background='#F4F3F3';
	}
	if(itemID!="CODE"){
		get_id(finalID).style.fontSize="9px";
		get_id(finalID).innerHTML=msg;
		get_id(finalID).style.height="auto";
		get_id(finalID).style.fontFamily="Tahoma";
	}
}
var location1=null;
var contact_flag=false;
var ctrlPressed=0;
var altPressed=0;
var shiftPressed=0;
function initiate_validation_career(form_id){
	bad="<span style='color:#F68720;'>Invalid</span>";
	if(get_id(form_id)){
		var form_here=get_id(form_id);
		for(i=0;i<form_here.elements.length;i++){
			if(form_here.elements[i].getAttribute("lang"))
			{
				form_here.elements[i].style.border='#7F9DB9 1px solid';
				form_here.elements[i].onblur=function(){
				validate_field_career(this.id,this.getAttribute("lang"));
				}
			}
		}
	}
}
var check_valid1,check_valid2,check_valid3=false;
function validate_field_career(itemID,check_against,min_size){
	if(!min_size)min_size=0;
	var msg=good;
	if(get_id("validation"))
	{
		finalID="validation";
	}
	finalID=itemID+"_validation";
	switch(check_against){	
	case "not_empty":
		if(get_id(itemID).value.length==0){
			msg=bad;
		}else{
			msg=good;
		}
	break;
	case "email":
		if(matchit("[0-9]",get_id(itemID).value)==1){
			msg=bad;
		}		
		else if(check_email(get_id(itemID).value)==false){
			msg=bad;
		}
		else{
			msg=good;
		}	
	break;
	case "numerical":
		if(!IsNumeric(get_id(itemID).value)){
			msg=bad;
		}		
		else{
			msg=good;			
		}	
	break;
	case "empty_or_numerical":
		if(get_id(itemID).value!="" && !IsNumeric(get_id(itemID).value)){
			msg=bad;
		}		
	break;
	case "not_null":
		if(get_id(itemID).value.length!=5){
			msg=bad;
		}
		else{
			msg=good;
		}
	break;
	}
	if(get_id(itemID).getAttribute("min_size") &&  get_id(itemID).value.length<get_id(itemID).getAttribute("min_size")){ 
		if(get_id(itemID).getAttribute("required") && 
		get_id(itemID).getAttribute("required")=="false" && get_id(itemID).value==""){
			msg=good;	
		}else{
			msg=bad;
		}
	}
	if(get_id(finalID)){
		get_id(finalID).style.display="block";
		get_id(finalID).style.fontSize="9px";
		get_id(finalID).innerHTML=msg;
		get_id(finalID).style.height="auto";
		get_id(finalID).style.fontFamily="Tahoma";
	}	
	if(msg.indexOf(bad)>-1){
		get_id(itemID).style.background='#F4E9E6';
		get_id(itemID).style.border='#7F9DB9 1px solid';		
		return false;
	}
	else{
		get_id(itemID).style.background='#F4F3F3';
		get_id(itemID).style.border='#7F9DB9 1px solid';		
		return true;		
	}	
}

function IsNumeric(sText){
   var ValidChars = "0123456789.+";
   var IsNumber=true;
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      if (ValidChars.indexOf(sText.charAt(i)) == -1){IsNumber = false;}
   }
   return IsNumber;
}
function display_job_description(){
	$('job_description_container').style.display='block';	
}
function show_jop_description(){
	value=$("jobs_info").value;
	sR("show_jop_description.php",'id='+value,'POST','job_description_container');
}
function fillCity(code)
{
	sR('../../modules/cities.php?thecode='+code,'','GET','city_container');
	
}
function fillCity2(code)
{
	sR('../../modules/cities.php?thecode='+code,'','GET','city_container2');
	
}
function fillCity3(code)
{
	sR('../../modules/cities.php?thecode='+code,'','GET','city_container3');
	
}
