var LANG = "EN";
var ALLREGION = "";
var SELECTREGION = "";
var ALLCITIES = "";
var SELECTCITIES = "";
var ALLAREA = "";
var SELECTAREAS = "";
var ALLADDRESSES = "";
var SELECTADDRESSES = "";
var GolbName = "";
var GolbScript = "";
var GlobId = "";
var div = "";
var MENU_FOCUSED = false;
var div2 = "";
var MENU_FOCUSED2 = false;
var SIZE = "";

function ShowDivs(code, imagePath){
	if(document.getElementById(code).style.visibility == 'hidden'){
		document.getElementById(code).style.visibility = 'visible';
		document.getElementById(code).style.display = 'block';
		document.getElementById('img_'+code).src='/images/'+imagePath+'/yelarrow2.gif';
	}else{
		document.getElementById(code).style.visibility = 'hidden';
		document.getElementById(code).style.display = 'none';
		document.getElementById('img_'+code).src='/images/'+imagePath+'/yelarrow2.gif';
	}
}


ARRAY = new Array();

var NUM = 0;
var CAT_ID = 0;
function setSize(size,cat_id){
	SIZE = size;
	CAT_ID = cat_id;
	ARRAY[CAT_ID] = new Array(SIZE);
}

function addToArray(cat_id,id,en_cat,ar_cat,lurl){
	if(id != '' && en_cat != '' && ar_cat && lurl != ''){
		ARRAY[CAT_ID][NUM] = id+','+en_cat+','+ar_cat+','+lurl;
		NUM = NUM+1;
	}
}

function clearAll(){
	document.editAdd.id1.value = '';
	document.editAdd.EN_linkName1.value = '';
	document.editAdd.FR_linkName1.value ='';
	document.editAdd.link1.value = '';
	document.editAdd.id2.value = '';
	document.editAdd.EN_linkName2.value = '';
	document.editAdd.FR_linkName2.value ='';
	document.editAdd.link2.value = '';
	document.editAdd.id3.value = '';
	document.editAdd.EN_linkName3.value = '';
	document.editAdd.FR_linkName3.value ='';
	document.editAdd.link3.value = '';

}


function ValidateLinks(){
	var pattern = /^([a-zA-Z0-9_-])+(\.[a-zA-Z]+)+(\.[a-zA-Z]+)*$/;
	var enName = document.editAdd.EN_linkName1.value
	var arName = document.editAdd.FR_linkName1.value
	var links = document.editAdd.link1.value;
	if(enName == ''){
		alert('please insert English link name');
		document.editAdd.EN_linkName1.focus();
		return false;
	}
	if(arName == ''){
		alert('please insert Arabic link name');
		document.editAdd.FR_linkName1.focus();
		return false;
	}
	if(links == ''){
		alert('please insert A valid URL ex \n www.pajesjaunes.com.lb');
		document.editAdd.link1.focus();
		return false;
	}
	flag = links.match(pattern);
	if(!flag){
		alert('please insert A valid URL ex \n www.pajesjaunes.com.lb');
		document.editAdd.link1.focus();
		return false;
	}

	var enName2 = document.editAdd.EN_linkName2.value
	var arName2 = document.editAdd.FR_linkName2.value
	var links2 = document.editAdd.link2.value;
	found1 = 0;
	if(enName2 != ''){
		found1 = 1;
	}
	if(arName2 != ''){
		found1 = 1;
	}
	if(links2 != ''){
		found1 = 1;
	}

	if(found1 == 1){
		if(enName2 == ''){
			alert('please insert English link name');
			document.editAdd.EN_linkName2.focus();
			return false;
		}
		if(arName2 == ''){
			alert('please insert Arabic link name');
			document.editAdd.FR_linkName2.focus();
			return false;
		}
		if(links2 == ''){
			alert('please insert A valid URL ex \n www.pajesjaunes.com.lb');
			document.editAdd.link2.focus();
			return false;
		}
		flag2 = links2.match(pattern);
		if(!flag2){
			alert('please insert A valid URL ex \n www.pajesjaunes.com.lb');
			document.editAdd.link2.focus();
			return false;
		}
	}
	var enName3 = document.editAdd.EN_linkName3.value
	var arName3 = document.editAdd.FR_linkName3.value
	var links3 = document.editAdd.link3.value;
	found2 = 0;
	if(enName3 != ''){
		found2 = 1;
	}
	if(arName3 != ''){
		found2 = 1;
	}
	if(links3 != ''){
		found2 = 1;
	}

	if(found2 == 1){
		if(enName3 == ''){
			alert('please insert English link name');
			document.editAdd.EN_linkName3.focus();
			return false;
		}
		if(arName3 == ''){
			alert('please insert Arabic link name');
			document.editAdd.FR_linkName3.focus();
			return false;
		}
		if(links3 == ''){
			alert('please insert A valid URL ex \n www.pajesjaunes.com.lb');
			document.editAdd.link3.focus();
			return false;
		}
		flag3 = links3.match(pattern);
		if(!flag3){
			alert('please insert A valid URL ex \n www.pajesjaunes.com.lb');
			document.editAdd.link3.focus();
			return false;
		}
	}

}



function listLinks(){
	var id = document.editAdd.cat[document.editAdd.cat.selectedIndex].value;
	param = '?id='+id;
	makeRequest2('/xml/links.php',param);
	if(id == ''){
		document.getElementById('linksForm').style.visibility = 'hidden';
		document.getElementById('linksForm').style.display = 'none';
	}else{
		document.getElementById('linksForm').style.visibility = 'visible';
		document.getElementById('linksForm').style.display = 'block';
	}
}


isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

function ddInit(e){
	topDog=isIE ? "BODY" : "HTML";
	whichDog=isIE ? document.all.theLayer : document.getElementById("theLayer");
	hotDog=isIE ? event.srcElement : e.target;
	while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
		hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
	}
	if (hotDog.id=="titleBar"){
		offsetx=isIE ? event.clientX : e.clientX;
		offsety=isIE ? event.clientY : e.clientY;
		nowX=parseInt(whichDog.style.left);
		nowY=parseInt(whichDog.style.top);
		ddEnabled=true;
		document.onmousemove=dd;
	}
}

function dd(e){
	if (!ddEnabled) return;
	whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
	whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
	return false;
}

function ddN4(whatDog){
	if (!isN4) return;
	N4=eval(whatDog);
	N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
	N4.onmousedown=function(e){
		N4.captureEvents(Event.MOUSEMOVE);
		N4x=e.x;
		N4y=e.y;
	}
	N4.onmousemove=function(e){
		if (isHot){
			N4.moveBy(e.x-N4x,e.y-N4y);
			return false;
		}
	}
	N4.onmouseup=function(){
		N4.releaseEvents(Event.MOUSEMOVE);
	}
}

function hideMe(){
	if (isIE||isNN) whichDog.style.visibility="hidden";
	else if (isN4) document.theLayer.visibility="hide";
}

function showMe(){
	if (isIE||isNN) whichDog.style.visibility="visible";
	else if (isN4) document.theLayer.visibility="show";
	document.getElementById("titleLayer").innerHTML = "Add Contact Information";
	document.contact.english_category.value = '';
	document.contact.arabic_category.value = '';
	document.contact.id.value = '';
	document.contact.website.value = '';
	document.contact.email.value = '';
	document.contact.phone.value = '';
	document.contact.phone2.value = '';
	document.contact.phone3.value = '';
}

function showMe2(id,ar_category_name,category_name,website,link_address,phone_number1,phone_number2,phone_number3){
	if (isIE||isNN) whichDog.style.visibility="visible";
	else if (isN4) document.theLayer.visibility="show";
	document.getElementById("titleLayer").innerHTML = "Edit Contact Information";
	document.contact.english_category.value = category_name;
	document.contact.arabic_category.value = ar_category_name;
	document.contact.id.value = id;
	document.contact.website.value = website;
	document.contact.email.value = link_address;
	document.contact.phone.value = phone_number1;
	document.contact.phone2.value = phone_number2;
	document.contact.phone3.value = phone_number3;
}

function showMe3(id,ar_category_name,category_name){
	whichDog.style.left = "-130";
	whichDog.style.top = "240";
	if (isIE||isNN) whichDog.style.visibility="visible";
	else if (isN4) document.theLayer.visibility="show";
	if(id == '' && ar_category_name == '' && category_name == ''){
		document.getElementById("titleLayer").innerHTML = "Add Link Categories";
	}else{
		document.getElementById("titleLayer").innerHTML = "Edit Link Categories";
	}
	document.cat.english_category.value = category_name;
	document.cat.arabic_category.value = ar_category_name;
	document.cat.id.value = id;
}

function showMe4(id,ar_title,en_title,ar_text,en_text){
	whichDog.style.left = "-50";
	whichDog.style.top = "240";
	if (isIE||isNN) whichDog.style.visibility="visible";
	else if (isN4) document.theLayer.visibility="show";
	if(id == '' && ar_title== '' && en_title== '' && ar_text== '' && en_text== ''){
		document.getElementById("titleLayer").innerHTML = "Add Product";
		document.getElementById("logoLayer").innerHTML = "";
	}else{
		document.getElementById("titleLayer").innerHTML = "Edit Product";
		document.getElementById("logoLayer").innerHTML = "In case you want to keep the same image, leave the logo field empty";
	}
	document.prod.arabic_title.value = ar_title;
	document.prod.english_title.value = en_title;
	document.prod.english_text.value = en_text;
	document.prod.arabic_text.value = ar_text;
	document.prod.id.value = id;
}


function showMe5(id,ar_text,en_text){
	whichDog.style.left = "-130";
	whichDog.style.top = "240";
	if (isIE||isNN) whichDog.style.visibility="visible";
	else if (isN4) document.theLayer.visibility="show";
	if(id == '' && ar_text== '' && en_text== ''){
		document.getElementById("titleLayer").innerHTML = "Add Announcement";
	}else{
		document.getElementById("titleLayer").innerHTML = "Edit Announcement";
	}
	document.announ.english_text.value = en_text;
	document.announ.arabic_text.value = ar_text;
	document.announ.id.value = id;
}


function validateAddProduct(){
	var root=document.prod;

	if(root.english_title.value==''){
		alert('Please provide an english title');
		root.english_title.focus();
		return false;
	}
	if(root.english_text.value==''){
		alert('Please provide an english text');
		root.english_text.focus();
		return false;
	}
	if(root.arabic_title.value==''){
		alert('Please provide an arabic title');
		root.arabic_title.focus();
		return false;
	}
	if(root.arabic_text.value==''){
		alert('Please provide an arabic text');
		root.arabic_text.focus();
		return false;
	}
	if(root.id.value==''){
		if(root.logo.value==''){
			alert('Please browse an image.');
			root.logo.focus();
			return false;
		}
	}

	return true;
}

function validateAddAnnouncement(){
	var root=document.announ;

	if(root.english_text.value==''){
		alert('Please provide an english text');
		root.english_text.focus();
		return false;
	}

	if(root.arabic_text.value==''){
		alert('Please provide an arabic text');
		root.arabic_text.focus();
		return false;
	}

	return true;
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");

function validateLinkCategory(){
	enC =  document.cat.english_category.value
	arC =  document.cat.arabic_category.value
	if(enC == ""){
		alert('Please insert ENGLISH category link');
		document.cat.english_category.focus();
		return false;
	}
	if(arC == ''){
		alert('Please insert FRENCH category link');
		document.cat.arabic_category.focus();
		return false;
	}
}

function validateContactInfo(){
	var root = document.contact;
	var english_category  = root.english_category.value;
	if(english_category == ''){
		alert('Please insert english category');
		root.english_category.focus();
		return false;
	}
	var arabic_category  = root.arabic_category.value;
	if(arabic_category == ''){
		alert('Please insert arabic category');
		root.arabic_category.focus();
		return false;
	}
	var phone = root.phone.value;
	if(phone == ''){
		alert('Please insert phone number');
		root.phone.focus();
		return false;
	}



}

function validateAboutUs(){
	var root = document.about;
	var Estblished  = root.established.value;
	if(Estblished == ''){
		alert("Please insert the year your company was established in.");
		root.established.focus();
		return false;
	}
	var legal  = root.legal.value;
	if(legal == ''){
		alert("Please insert your company legal status example \n \'SARL SAL LTD...\'");
		root.legal.focus();
		return false;
	}
	var capital  = root.capital.value;
	if(capital == ''){
		alert("Please insert your company capital example \n \'20 000 000 LL...\'");
		root.capital.focus();
		return false;
	}
	var num  = root.num_of_employees.value;
	if(num == ''){
		alert("Please insert your company number of employees.");
		root.num_of_employees.focus();
		return false;
	}
	var manager  = root.manager.value;
	if(manager == ''){
		alert("Please insert the company Nanager Name.");
		root.manager.focus();
		return false;
	}
	var sector  = root.sector.value;
	if(sector == ''){
		alert("Please insert your company sector.");
		root.sector.focus();
		return false;
	}

}

function passValidation(){
	var root = document.change_password;
	var oldp = root.old.value;
	var newp = root.newp.value;
	var confnew = root.confnew.value;

	if (oldp == '' || newp == '' || confnew == ''){
		alert('Please fill up all the fields');
		root.old.focus();
		return false;
	}
	if (!isNaN(newp)){
		alert('Please insert a password that contains characters.');
		root.newp.focus();
		return false;
	}

	if (newp != confnew){
		alert('The password and it\'s confirmation do not match');
		root.confnew.focus();
		return false;
	}

	oldp = hex_md5(oldp);
	newp = hex_md5(newp);
	confnew = hex_md5(confnew);

	root.old.value = oldp;
	root.newp.value = newp;
	root.confnew.value = confnew;
	root.enc.value = '1';

	return true;
}


function showLayer(lay,flag){
	if(lay == 'established2'){
		text = 'Please insert the year your company was established in.';
	}else if(lay == 'legal2'){
		text = 'Please insert your company legal status<br> example: <B>SARL, SAL, LTD</B>';
	}
	else if(lay == "capital2"){
		text = 'Please insert your company capital example 20 000 000 LL';
	}else if(lay == "num2"){
		text = "Please insert your company number of employees.";
	}else if(lay == "manager2"){
		text = "Please insert the company Nanager Name.";
	}else if(lay == "sector2"){
		text = "Please insert your company sector.";
	}else if(lay == "old2"){
		text = "Please insert your old password.";
	}else if(lay == "new2"){
		text = "Please insert your New Password.";
	}
	else if(lay == "confnew2"){
		text = "Please retype your new password.";
	}
	else if(lay == "encat2"){
		text = "Please insert/change english category name.<BR>(OBLIGATORY FIELD)";
	}
	else if(lay == "arcat2"){
		text = "Please insert/change arabic category name.<BR>(OBLIGATORY FIELD)";
	}
	else if(lay == "web2"){
		text = "Please insert/change Website Field.<BR>(NON OBLIGATORY FIELD)";
	}
	else if(lay == "email2"){
		text = "Please insert/change E-mail Filed.<BR>(NON OBLIGATORY FIELD)";
	}
	else if(lay == "fone12"){
		text = "Please insert/change first Phone Filed.<BR>(OBLIGATORY FIELD)";
	}
	else if(lay == "fone22"){
		text = "Please insert/change second Phone Filed.<BR>(NON OBLIGATORY FIELD)";
	}
	else if(lay == "fone32"){
		text = "Please insert/change third Phone Filed.<BR>(NON OBLIGATORY FIELD)";
	}else if(lay == "flink21-1"){
		text = "Please insert/change first english Link Filed.<BR>(OBLIGATORY FIELD) EX: Yellow Pages";
	}else if(lay == "flink21-2"){
		text = "Please insert/change first Arabic Link Filed.<BR>(OBLIGATORY FIELD) EX: Pages Jaunes";
	}else if(lay == "flink21-3"){
		text = "Please insert/change Link Filed.<BR>(OBLIGATORY FIELD) EX: www.pagesjaunes.com <BR>";
	}
	else if(lay == "flink22-1"){
		text = "Please insert/change Second english Link Filed.<BR>(NON OBLIGATORY FIELD) EX: Yellow Pages";
	}else if(lay == "flink22-2"){
		text = "Please insert/change Second Arabic Link Filed.<BR>(NON OBLIGATORY FIELD) EX: Pages Jaunes";
	}else if(lay == "flink22-3"){
		text = "Please insert/change Link Filed.<BR>(NON OBLIGATORY FIELD) EX: www.pagesjaunes.com <BR>";
	}

	else if(lay == "flink23-1"){
		text = "Please insert/change Third english Link Filed.<BR>(NON OBLIGATORY FIELD) EX: Yellow Pages";
	}else if(lay == "flink23-2"){
		text = "Please insert/change Third Arabic Link Filed.<BR>(NON OBLIGATORY FIELD) EX: Pages Jaunes";
	}else if(lay == "flink23-3"){
		text = "Please insert/change Link Filed.<BR>(NON OBLIGATORY FIELD) EX: www.pagesjaunes.com <BR>";
	}else if(lay == "logo"){
		text = "Click on the browse button to upload <br>your company logo from local PC.<BR>(OBLIGATORY FIELD)";
	}else if(lay == "enti"){
		text = "Please specify an english title.<BR>(OBLIGATORY FIELD)";
	}else if(lay == "arti"){
		text = "Please specify a arabic title.<BR>(OBLIGATORY FIELD)";
	}else if(lay == "ente"){
		text = "Please specify an english text.<BR>(OBLIGATORY FIELD)";
	}else if(lay == "arte"){
		text = "Please specify a arabic text.<BR>(OBLIGATORY FIELD)";
	}else if(lay == "p_logo"){
		text = "Please browse a logo.<BR>(OBLIGATORY FIELD)";
	}
	else if(lay =='company_name_en'){
		text ="Please specify the Company Name in English";
	}else if(lay =='company_name_ar'){
		text ="Please specify the Company Name in Arabic";
	}
	if(flag == 1){
		vis = "visible";
		eval("document.getElementById('"+lay+"_text').innerHTML='"+text+"';");
		eval("document.getElementById('"+lay+"_container').style.visibility = '"+vis+"';");
	}else{
		text = "";
		vis = "hidden";
		eval("document.getElementById('"+lay+"_text').innerHTML='"+text+"';");
		eval("document.getElementById('"+lay+"_container').style.visibility = '"+vis+"';");
	}



}




function setLang(lang){

	LANG = lang;

	if(LANG =="EN"){
		ALLCITIES = "You have selected All Regions";
		SELECTCITIES = "Please Select a Region from Above";
		ALLAREA = "You have selected All Areas";
		SELECTAREAS = "Please Select a City from Above";
		ALLADDRESSES = "You have selected All Addresses";
		SELECTADDRESSES = "Please Select an Area from Above";
	}else{
		ALLCITIES = "&#1575;&#1582;&#1578;&#1585;&#1578; &#1603;&#1604; &#1575;&#1604;&#1605;&#1581;&#1575;&#1601;&#1592;&#1575;&#1578;";
		SELECTCITIES = "&#1575;&#1604;&#1585;&#1580;&#1575;&#1569; &#1575;&#1582;&#1578;&#1575;&#1585; &#1575;&#1604;&#1605;&#1581;&#1575;&#1601;&#1592;&#1577; &#1605;&#1606; &#1575;&#1604;&#1575;&#1593;&#1604;&#1609;";
		ALLAREA = "&#1604;&#1602;&#1583; &#1602;&#1605;&#1578; &#1576;&#1575;&#1582;&#1578;&#1610;&#1575;&#1585; &#1603;&#1604; &#1575;&#1604;&#1605;&#1606;&#1575;&#1591;&#1602;";
		SELECTAREAS = "&#1575;&#1604;&#1585;&#1580;&#1575;&#1569; &#1575;&#1582;&#1578;&#1575;&#1585; &#1575;&#1604;&#1605;&#1583;&#1610;&#1606;&#1577; &#1605;&#1606; &#1575;&#1604;&#1575;&#1593;&#1604;&#1609;";
		ALLADDRESSES = "&#1604;&#1602;&#1583; &#1602;&#1605;&#1578; &#1576;&#1575;&#1582;&#1578;&#1610;&#1575;&#1585; &#1603;&#1604; &#1575;&#1604;&#1593;&#1606;&#1575;&#1608;&#1610;&#1606;";
		SELECTADDRESSES = "&#1575;&#1604;&#1585;&#1580;&#1575;&#1569; &#1575;&#1582;&#1578;&#1610;&#1575;&#1585; &#1575;&#1604;&#1605;&#1606;&#1591;&#1602;&#1577; &#1605;&#1606; &#1575;&#1604;&#1575;&#1593;&#1604;&#1609;";
	}

}

function invalid(){
	document.AS.active.value = '0';
}

function onBusinessChange(){
	
	document.AS.activity.value = '';
	document.AS.sub_actvity.value = '';
	document.AS.sub_actvity_value.value = '';
	document.AS.active.value = '0';
	document.AS.business1.value = '';
	document.AS.business2.value = '';
	document.AS.business3.value = '';
}

function levelTwo(Activity,name){
	//var bs = window.opener.document.AS.business.value = name;
	var bs = window.opener.document.AS.business.value = '';
	var hf2 =window.opener.document.AS.activity.value = Activity;
	var hf3 =window.opener.document.AS.sub_actvity.value = '';
	var hf4 =window.opener.document.AS.sub_actvity_value.value = '';
	var hf4 =window.opener.document.AS.active.value = '1';
	window.opener.document.AS.business1.value = name;
	window.opener.document.AS.business2.value = '';
	window.opener.document.AS.business3.value = '';
	window.opener.document.AS.search.focus();
	self.close();
}

function levelThree(activityName,ActId,name,subActivity){
	//var bs = window.opener.document.AS.business.value = activityName+'|'+name;
	var bs = window.opener.document.AS.business.value = '';
	var hf2 = window.opener.document.AS.activity.value = ActId;
	var hf3 = window.opener.document.AS.sub_actvity.value = subActivity;
	var hf4 = window.opener.document.AS.sub_actvity_value.value = '';
	var hf4 =window.opener.document.AS.active.value = '1';
	window.opener.document.AS.business1.value = activityName;
	window.opener.document.AS.business2.value = name;
	window.opener.document.AS.business3.value = '';
	window.opener.document.AS.search.focus();
	self.close();
}

function levelFour(activityName,ActId,name,subActivity,valuesr,valueCode){
	//var bs =window.opener.document.AS.business.value = activityName+'|'+name+'|'+valuesr;
	var bs =window.opener.document.AS.business.value = '';
	var hf2 =window.opener.document.AS.activity.value = ActId;
	var hf3 =window.opener.document.AS.sub_actvity.value = subActivity;
	var hf4 =window.opener.document.AS.sub_actvity_value.value = valueCode;
	var hf4 =window.opener.document.AS.active.value = '1';
	window.opener.document.AS.business1.value = activityName;
	window.opener.document.AS.business2.value = name;
	window.opener.document.AS.business3.value = valuesr;
	window.opener.document.AS.search.focus();
	self.close();
}


function shutDiv(){
	d = div;
	showLay(d,0);
}

function shutDiv2(){
	d = div2;
	showLay2(d,0);
}



function Delay(lay){
	MENU_FOCUSED = false;
	div = lay;
	setTimeout("shutDiv()",500);
	return;
}

function Delay2(lay){
	MENU_FOCUSED2 = false;
	div2 = lay;
	setTimeout("shutDiv2()",500);
	return;
}

function setMenuFocused() {
	MENU_FOCUSED = true;
}

function setMenuFocused2() {
	MENU_FOCUSED2 = true;
}


function showLay(lay,fl){
	if(fl == 1){
		setMenuFocused()
		vis = 'visible';
		document.getElementById(lay).style.visibility = vis;
	}else{
		vis = 'hidden';
		if (!MENU_FOCUSED){

			document.getElementById(lay).style.height = '1';
			document.getElementById(lay).style.visibility = vis;
		}
	}
}


function showLay2(lay,fl){
	if(fl == 1){
		setMenuFocused2()
		vis = 'visible';
		document.getElementById(lay).style.visibility = vis;
	}else{
		vis = 'hidden';
		if (!MENU_FOCUSED2){
			document.getElementById(lay).style.visibility = vis;
		}
	}
}



function ShowEx(flag){

	if(flag == 1){
		vis = 'visible';
	}else{
		vis = 'hidden';
	}
	document.getElementById('example').style.visibility = vis;
}

function ShowEx2(flag){

	if(flag == 1){
		vis = 'visible';
	}else{
		vis = 'hidden';
	}
	document.getElementById('example2').style.visibility = vis;
}


function validateQuickSearch(){
	var root = document.qs;
	var search = root.QS.value;
	if(search == ''){
		alert('Please insert you search crieteria.');
		root.QS.focus();
		return false;
	}
	var opt1 = root.any[0].checked;
	var opt2 = root.any[1].checked;

	if(opt1 == false && opt2 == false){
		alert('Please choose if All Words or Any Words option');
		root.any[0].focus();
		return false;
	}
}

function validateAdvSearch(){
	var root = document.AS;
	var search = root.search.value;
	if(search == ''){
		//alert('Please insert you search crieteria.');
		//root.search.focus();
		return true;
	}
	else{
		document.AS.business1.disabled = false;
		document.AS.business2.disabled = false;
		document.AS.business3.disabled = false;
		return true;
	}
}

function makeRequest(url, parameters,name,scrit,theId) {

	GolbName = name;
	GolbScript = scrit;
	GlobId = theId;
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = alertContents;
	http_request.open('GET', url + parameters, true);
	http_request.send(null);
}



function makeRequest2(url, parameters) {

	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = alertContents2;
	http_request.open('GET', url + parameters, true);
	http_request.send(null);
}


function alertContents2() {


	if (http_request.readyState == 4) {
		if (http_request.status == 200) {

			xmldoc = http_request.responseXML;
			ro = xmldoc.getElementsByTagName('cat').item(0);
			len = ro.childNodes.length;

			var id =  ro.childNodes.item(1).childNodes.item(0).data;
			var enName =  ro.childNodes.item(3).childNodes.item(0).data;
			var arName =  ro.childNodes.item(5).childNodes.item(0).data;
			var url1 =  ro.childNodes.item(7).childNodes.item(0).data;
			if(id == 'empty') id = '';
			if(enName == 'empty') enName = '';
			if(arName == 'empty') arName = '';
			if(url1 == 'empty') url1 = '';



			document.editAdd.id1.value = id;
			document.editAdd.FR_linkName1.value = arName;
			document.editAdd.EN_linkName1.value = enName;
			document.editAdd.link1.value = url1;


			var id2 =  ro.childNodes.item(9).childNodes.item(0).data;
			var enName2 =  ro.childNodes.item(11).childNodes.item(0).data;
			var arName2 =  ro.childNodes.item(13).childNodes.item(0).data;
			var url2 =  ro.childNodes.item(15).childNodes.item(0).data;
			if(id2 == 'empty') id2 = '';
			if(enName2 == 'empty') enName2 = '';
			if(arName2 == 'empty') arName2 = '';
			if(url2 == 'empty') url2 = '';
			document.editAdd.id2.value = id2;
			document.editAdd.FR_linkName2.value = arName2;
			document.editAdd.EN_linkName2.value = enName2;
			document.editAdd.link2.value = url2;

			var id3 =  ro.childNodes.item(17).childNodes.item(0).data;
			var enName3 =  ro.childNodes.item(19).childNodes.item(0).data;
			var arName3 =  ro.childNodes.item(21).childNodes.item(0).data;
			var url3 =  ro.childNodes.item(23).childNodes.item(0).data;
			if(id3 == 'empty') id3 = '';
			if(enName3 == 'empty') enName3 = '';
			if(arName3 == 'empty') arName3 = '';
			if(url3 == 'empty') url3 = '';
			document.editAdd.id3.value = id3;
			document.editAdd.FR_linkName3.value = arName3;
			document.editAdd.EN_linkName3.value = enName3;
			document.editAdd.link3.value = url3;
			document.getElementById("DIV_IMG").innerHTML = "";

		}else{
			alert('There was a problem with the request.');
		}
	}
	else{
		document.getElementById("DIV_IMG").innerHTML = "<img src=\"/images/loading.gif\" align=\"absmiddle\">&nbsp;loading ... ";

	}
}










function alertContents() {


	if (http_request.readyState == 4) {
		if (http_request.status == 200) {

			xmldoc = http_request.responseXML;
			ro = xmldoc.getElementsByTagName('msg').item(0);
			len = ro.childNodes.length;
			data = "";

			for (var iNode = 0; iNode < len; iNode++) {
				if(GlobId == ro.childNodes.item(iNode).childNodes.item(0).data){
					as = 'selected';
				}else{
					as = '';
				}
				data += '<option value=\"'+ro.childNodes.item(iNode).childNodes.item(0).data+'\" '+as+'>'
				data += ro.childNodes.item(iNode+1).childNodes.item(0).data +'</option>';
				iNode++
			}
			//alert(GolbName);
			// all = "<select name=\""+GolbName+"\" onChange=\""+GolbScript+"\"><option value=\"\">Select Below</option>" + data + "</select>";
			all = "<select name=\""+GolbName+"\" onChange=\""+GolbScript+"\">" + data + "</select>";

			eval('document.getElementById("'+GolbName+'").innerHTML =\''+all+'\';');

		}else{
			alert('There was a problem with the request.');
		}
	}
	else{
		eval('document.getElementById("'+GolbName+'").innerHTML = "loading ... ";');
	}
}









function displayCities(cityId){

	if(cityId == undefined){
		areaId = '';
	}

	id = document.AS.regions[document.AS.regions.selectedIndex].value;
	
	if(id == ''){
		document.getElementById("cities").innerHTML = ALLCITIES;

	}else if(id == 'all'){
		document.getElementById("cities").innerHTML = ALLCITIES;
	}
	else{
		param = '?id='+id;
		makeRequest('/xml/cities.php',param,"cities","return ;",cityId);
	}
}

function openCat(){
	window.open('/categories.php','Categories','width=450,height=500,scrollbars=1,menubars=0,left=580,top=120');
	return false;
}

function checkLogo(){
	var root = document.logo;
	var file = root.new_logo;
	if(file.value==''){
		alert("Please Browse for a new logo image before you continue");
		file.focus();
		return false;
	}
	return true;
}
function validateCompanyInfo(){
	var root = document.welcome_company_info;
	var en_name = root.en_name;
	var ar_name = root.en_name;
	
	if(en_name.value==''){
		alert("Please enter the company name in English");
		en_name.focus();
		return false;
	}
	if(ar_name.value==''){
		alert("Please enter the company name in Arabic");
		ar_name.focus();
		return false;
	}
	return true;
}

function ValidateInfoForm(){
	var root = document.InfoForm;
	var name = root.name;
	var email = root.email;
	var contactupdate = root.contactupdate;
	
	if(name.value==''){
		alert("Please enter your name");
		name.focus();
		return false;
	}
	if(email.value==''){
		alert("Please enter your email");
		email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var flag = email.value.match(pattern);
	if(!flag){
		alert("Please enter a valid email address");
		email.focus();
		return false;
	}
	if(contactupdate.value==''){
		alert("Please enter your message");
		email.focus();
		return false;
	}
	return true;
}


function replaceBusinessAndSubmit(businessName){
	root=document.AS;
	
	root.business.value=businessName;
	root.submit();
}