function displayNewUpdateRow(displayRow,hideRow){
	document.getElementById(displayRow).style.display = ''
	document.getElementById(hideRow).style.display = 'none'
}

function displayMakeLayer(displayRow,allRowsCount,theName){
	for (var i=0 ; i<allRowsCount ; i++){
		try{
			if (document.getElementById('makeModel'+i) != document.getElementById(displayRow)){
				document.getElementById('makeModel'+i).style.display = 'none'
				document.getElementById('show'+i).innerHTML = 'Show Models'
			}
		}catch(E){}
	}
	if (document.getElementById(displayRow).style.display == ''){
		document.getElementById(displayRow).style.display = 'none'
		theName.innerHTML = 'Show Models'
	}else{
		document.getElementById(displayRow).style.display = ''
		theName.innerHTML = 'Hide Models'
	}
	
}


function displayCarTermLayer(displayRow,allRowsCount,theName){
	for (var i=0 ; i<allRowsCount ; i++){
		try{
			if (document.getElementById('CarTerm'+i) != document.getElementById(displayRow)){
				document.getElementById('CarTerm'+i).style.display = 'none'
				document.getElementById('show'+i).innerHTML = 'Show Car Terms'
			}
		}catch(E){}
	}
	if (document.getElementById(displayRow).style.display == ''){
		document.getElementById(displayRow).style.display = 'none'
		theName.innerHTML = 'Show Car Terms'
	}else{
		document.getElementById(displayRow).style.display = ''
		theName.innerHTML = 'Hide Car Terms'
	}
	
}

function displayShowRoomLayer(displayRow,allRowsCount,theName){
	for (var i=0 ; i<allRowsCount ; i++){
		try{
			if (document.getElementById('SRU'+i) != document.getElementById(displayRow)){
				document.getElementById('SRU'+i).style.display = 'none'
			}
			if (document.getElementById('SRC'+i) != document.getElementById(displayRow)){
				document.getElementById('SRC'+i).style.display = 'none'
			}
			if (document.getElementById('SRUsers'+i) != document.getElementById(displayRow)){
				document.getElementById('SRUsers'+i).style.display = 'none'
			}
			try{document.getElementById('viewCars'+i).value = "View Cars"}catch(E){}
			try{document.getElementById('viewUsers'+i).value = "View Users"}catch(E){}
		}catch(E){}
	}
	if (document.getElementById(displayRow).style.display == ''){
		document.getElementById(displayRow).style.display = 'none'
	}else{
		document.getElementById(displayRow).style.display = ''
	}
}

function displayShowRoomCarsLayer(displayRow,allRowsCount,theName){
	for (var i=0 ; i<allRowsCount ; i++){
		try{
			if (document.getElementById('SRC'+i) != document.getElementById(displayRow)){
				document.getElementById('SRC'+i).style.display = 'none'
			}
			if (document.getElementById('SRU'+i) != document.getElementById(displayRow)){
				document.getElementById('SRU'+i).style.display = 'none'
			}
			if (document.getElementById('SRUsers'+i) != document.getElementById(displayRow)){
				document.getElementById('SRUsers'+i).style.display = 'none'
			}
			try{document.getElementById('viewCars'+i).value = "View Cars"}catch(E){}
			try{document.getElementById('viewUsers'+i).value = "View Users"}catch(E){}
		}catch(E){}
	}
	if (document.getElementById(displayRow).style.display == ''){
		document.getElementById(displayRow).style.display = 'none'
		document.getElementById(theName.name).value = "View Cars"
	}else{
		document.getElementById(displayRow).style.display = ''
		document.getElementById(theName.name).value = "Hide Cars"
	}
}

function displayShowRoomUsersLayer(displayRow,allRowsCount,theName){
	for (var i=0 ; i<allRowsCount ; i++){
		try{
			if (document.getElementById('SRUsers'+i) != document.getElementById(displayRow)){
				document.getElementById('SRUsers'+i).style.display = 'none'
			}
			if (document.getElementById('SRC'+i) != document.getElementById(displayRow)){
				document.getElementById('SRC'+i).style.display = 'none'
			}
			if (document.getElementById('SRU'+i) != document.getElementById(displayRow)){
				document.getElementById('SRU'+i).style.display = 'none'
			}
			try{document.getElementById('viewCars'+i).value = "View Cars"}catch(E){}
			try{document.getElementById('viewUsers'+i).value = "View Users"}catch(E){}
		}catch(E){}
	}

	if (document.getElementById(displayRow).style.display == ''){
		document.getElementById(displayRow).style.display = 'none'
		document.getElementById(theName.name).value = "View Users"
	}else{
		document.getElementById(displayRow).style.display = ''
		document.getElementById(theName.name).value = "Hide Users"
	}
}

function displayServiceLayer(displayRow,allRowsCount,theName){
	for (var i=0 ; i<allRowsCount ; i++){
		try{
			if (document.getElementById('serviceUPT'+i) != document.getElementById(displayRow)){
				document.getElementById('serviceUPT'+i).style.display = 'none'
			}
		}catch(E){}
	}

	if (document.getElementById(displayRow).style.display == ''){
		document.getElementById(displayRow).style.display = 'none'
	}else{
		document.getElementById(displayRow).style.display = ''
	}
}

function validate_delete(NForm){
	if (window.confirm("Are you sure you want to delete this?")){
		NForm.submit();
	}
	return false;
}

function validate_MakesForm(NForm){
	if (NForm.makesName.value == "" || NForm.makesURL.value == ""){
		alert("All Fields are Required")
		return false;
	}
	return true;
}

function validateUpload(NForm){
	if (NForm.f_userfile.value == ""){
		alert("Select a file to upload")
		return false;
	}
	return true;
}

function validate_ModelForm(NForm){
	if (NForm.modelName.value == ""){
		alert("All Fields are Required")
		return false;
	}
	return true;
}

function validate_CTCatForm(NForm){
	if (NForm.CTCatNameEN.value == ""){
		alert("All Fields are Required")
		return false;
	}
	return true;
}

function validate_CTermForm(NForm){
	if (NForm.EnCarTermName.value == "" || NForm.ArCarTermName.value == ""){
		alert("All Fields are Required")
		return false;
	}
	return true;
}

function validate_addShowRoom(NForm){
	if (NForm.SRNameEN.value == "" || NForm.SRPhone.value == "" || NForm.SREmail.value == "" || NForm.cityID.value == "" || NForm.SRAddressEN.value == ""){
		alert("All Fields are Required")
		return false;
	}
	NForm.SREmail.focus();
        var str = NForm.SREmail.value;
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if (!reg1.test(str) && reg2.test(str)){
		return true;
	}else{
		alert("Use a Valid Email")
		return false;
	}
	return true;
}

function  validateSendFriend(NForm){
	if (NForm.YourName.value == "" || NForm.YourEmail.value == "" || NForm.recipientEmail.value == ""){
		alert("All Fields are Required")
		return false;
	}
	NForm.YourEmail.focus();
        var str = NForm.YourEmail.value;
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if (!reg1.test(str) && reg2.test(str)){
		return true;
	}else{
		alert("Use a Valid Email")
		return false;
	}
	return true;
}

function loadModel(tagName){
	modelFrame.location='Man-makeModels.asp?makeID='+tagName.value
	document.getElementById("modelID").value=""
}

function loadSearchModel(makeID,modelID){
	modelSearchFrame.location='carModels.asp?models='+modelID+'&makes='+makeID
	document.getElementById("models").value=""
}

function loadSearchSeller(seller,locations){
	sellerSearchFrame.location='carSellers.asp?sellers='+seller+'&locations='+locations
	document.getElementById("sellers").value=""
}

function loadCity(countryID,cityID){
	citiesFrame.location='/cities.asp?countryID='+countryID.value+'&cityID='+cityID
	parent.document.getElementById("cityID").value=""
}

function loadCityMultipleForm(countryID,cityID,frameName,formName){
	document.getElementById(frameName).src='/cities.asp?countryID='+countryID.value+'&cityID='+cityID+'&formName='+formName
	document.getElementById(formName).cityID.value=""
}

function loadCityMultipleFormForContyactForm(countryID,cityID,frameName,formName){
	document.getElementById(frameName).src='/cities.asp?cityIDName=cityIDC&countryID='+countryID.value+'&cityIDC='+cityID+'&formName='+formName
	document.getElementById(formName).cityIDC.value=""
}

function openPic(PicPath){
	window.open(PicPath,'windowPic','width=800,height=600,menubar=0,status=0,resizable=1,scrollbars=1')
}

function validate_addListing(NForm){
	if (NForm.CompanyName.value == "" || NForm.cityID.value == "" || NForm.categoryID.value == ""){
		alert("Fill out required fields")
		return false;
	}
}

function validate_RSSForm(NForm){
	if (NForm.AutoNewsEN.value == "" || NForm.AutoEventsEN.value == "" || NForm.AutoReviewsEN.value == ""){
		alert("All Fields are Required")
		return false;
	}
}

function validate_Listshowroom(NForm){
	if (NForm.FullName.value == "" || NForm.telephone.value == "" || NForm.email.value == "" || NForm.ShowroomName.value == "" || NForm.cityIDC.value == ""){
		alert("Fill All Required Fields")
		return false;
	}
	var str = NForm.email.value;
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
        if (!reg1.test(str) && reg2.test(str)) {
                return true;
        }else{
                alert ("Enter A valid Email");
                return false; 
        }
}
//========================================================================================
function ap(text) {
	document.getElementById("slidebutton").value  = (text == "Stop") ? "Start" : "Stop";
	rotate();
}

function hideSShow(){
	document.getElementById("slidebutton").value = "Start";
	document.getElementById("SShowDiv").style.display = 'none';
	document.getElementById("carSpecTable").style.display = '';
}

function rotate() {
	if (document.getElementById("slidebutton").value == "Stop") {
		if (current < photoSShowArray.length-1) {
				nextImg();
			} else {
				firstImg();
		}		
		window.setTimeout("rotate()", rotate_delay);
 	}
}

function firstImg()	{		
	current = 0;	
	showSlideShowDiv(photoSShowArray[current],current);
}

function lastImg()	{		
	current = photoSShowArray.length - 1;	
	showSlideShowDiv(photoSShowArray[current],current);
}

function nextImg()	{	
	if (current<photoSShowArray.length-1) {	
		current=parseInt(current) + 1;	
		showSlideShowDiv(photoSShowArray[current],current);
	}
}

function prevImg()	{		
	if (current>0) {	
		current=parseInt(current) - 1;	
		showSlideShowDiv(photoSShowArray[current],current);	
	}
}

function showSlideShowDiv(pic,pos){
	current=pos;
	document.location="#photosTOP";	
	document.getElementById("SShowDiv").style.display = '';
	var fileimagepath = path + pic;
	document.getElementById("SShowImage").src = fileimagepath;
	return false;
}
//========================================================================================
function zammoor_start_show(){
	// Time is in seconds X 1000
	setInterval("zammoor_slideshow()", 10000);
}
 
function zammoor_slideshow(){
	cell_num++;
	if (cell_num == cellshow.length){
		cell_num = 0;
	}
	document.getElementById('rotating_cell').innerHTML = cellshow[cell_num];
}
//========================================================================================
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function isnull(v){
        return((v+"" == 'null') || (v+"" =='undefined') || (String(v+"").length==0));
}
//========================================================================================
var iRef_Mouse = 1;
var iRef_Focus = 2;
var iRef_First = 3;
var iRef_Last = 4;

var iWhere_Before = 1;
var iWhere_After = 2;

var number_of_Clones = -1;

/*
	Name		=	addTableRow
	Module		=	MultiRow
	Version		=	1.5
*/
function addTableRow(oTable, iRef, iWhere){
	var refTRIndex;
	var trindex;
	var trows_length = oTable.rows.length;

	switch(iRef){
	case iRef_Mouse:{
			// still under work
			alert(event.clientX);
			var sourceElement = document.body.componentFromPoint(event.clientX-100, event.clientY);
			if(sourceElement!=""){
				// now we have to go all the way up until we hit a table element or the document element.
				var nCount = 0;
				while(true && nCount < 10){
					alert(sourceElement.onClick);
					sourceElement = sourceElement.parentNode;
					nCount ++;
				}
				alert(mouseTR);
				var mouseTR;
				refTRIndex = mouseTR.rowIndex;
			}
			break;
		}
	case iRef_Focus:{
			var focusTR = document.activeElement.parentElement.parentElement;
			refTRIndex = focusTR.rowIndex;
			break;
		}
	case iRef_First:{
			break;
		}
	case iRef_Last:{
			refTRIndex = -1;
			break;
		}
	}
	
	switch(iWhere){
	case iWhere_Before:{
			if(refTRIndex==-1){
				trindex = trows_length;
			}else{
				trindex = refTRIndex;
			}
			break;
		}
	case iWhere_After:{
			if(refTRIndex==-1){
				trindex = -1;
			}else{
				trindex = refTRIndex + 1;
			}
			break;
		}
	}

	var oTR = addSimiliarRow(oTable, refTRIndex, trindex, iWhere);
	
	if(arguments[3]){
		// some function to call
		arguments[3](oTR);
	}else{
		// just do nothing
	}
}


/*
	Name		=	addSimiliarRow
	Module		=	MultiRow
	Version		=	1.0
*/
function addSimiliarRow(oTable, refTRIndex, trindex, iWhere){
	var oTR = oTable.rows.item(refTRIndex).cloneNode(true);
	if(iWhere==iWhere_Before){
		oTable.insertBefore(oTR, oTable.rows.item(refTRIndex));
	}else{
		try{
			oTable.insertBefore(oTR, oTable.rows.item(refTRIndex+1));
		}catch(e){
		}
	}

	number_of_Clones++;
	return oTR;
}

function delete_tr(zFunc){
	var oTR = document.activeElement.parentElement.parentElement;
	var oTable = oTR.parentElement;
	if (number_of_Clones > -1){
		oTable.removeChild(oTR);
		number_of_Clones --;
	}else{
		if(zFunc == "true")
			show_exTime()
		CleanTR(oTR)
	}
}

function new_tr(x,remove,zFunc){
	var oTR = document.activeElement.parentElement.parentElement;
	var oTable = oTR.parentElement;
	addTableRow(oTable, iRef_Focus, iWhere_After, CleanTR);
	if (zFunc == "true")
		oTR.cells(x).getElementsByTagName("A").item(0).href="javascript:delete_tr('true')";
	else
		oTR.cells(x).getElementsByTagName("A").item(0).href="javascript:delete_tr()";
	oTR.cells(x).getElementsByTagName("A").item(0).innerHTML="[-]";
}

function CleanTR(oTR){
	// do whatever we want to the new TR
	var oTR_cells = oTR.cells;
	var oTR_cells_length = oTR.cells.length;
	for(var i=0; i<oTR.cells.length; i++){
		var oTR_cells_i_INPUT = oTR.cells(i).getElementsByTagName("INPUT");
		var oTR_cells_i_INPUT_length = oTR_cells_i_INPUT.length;
		for(var j=0; j<oTR_cells_i_INPUT_length; j++){
			oTR_cells_i_INPUT.item(j).value = "";
		}

		var oTR_cells_i_SELECT = oTR.cells(i).getElementsByTagName("SELECT");
		var oTR_cells_i_SELECT_length = oTR_cells_i_SELECT.length;
		for(var j=0; j<oTR_cells_i_SELECT_length; j++){
			oTR_cells_i_SELECT.item(j).selectedIndex = 3;
		}

		var oTR_cells_i_textarea = oTR.cells(i).getElementsByTagName("textarea");
		var oTR_cells_i_textarea_length = oTR_cells_i_textarea.length;
		for(var j=0; j<oTR_cells_i_textarea_length; j++){
			oTR_cells_i_textarea.item(j).value = "";
		}
	}
}
//========================================================================
function Validate_changePassword(NForm){ 
        if(NForm.oldpassword.value=="" || NForm.newpassword.value=="" || NForm.confnewpassword.value==""){ 
                alert("All fields are required");
                return false;
        }
        if (NForm.newpassword.value != NForm.confnewpassword.value){
		alert("New and confirmed Password does not match");
		NForm.newpassword.value= ''
		NForm.confnewpassword.value =''
                return false;
	}
	return true;
}

function IsValidEmail(NForm){
	NForm.username.focus();
        var str = NForm.username.value;
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
        if (!reg1.test(str) && reg2.test(str)) {
                return true;
        }else{
                alert ("Enter A valid Email");
                return false; 
        }
	return false;
}

function handleOnNumbers(e){
	var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if ((key > 95 && key < 106) || (key > 47 && key < 58) || (key == 46) || (key == 8) || (key == 37) || (key == 39))
		return true;
	else
		return false;
}

function ShowContactFormShowroom(){		
	document.getElementById("ContactFormShowroom").style.display = '';
	try{
		document.getElementById("UserExplainLogin").style.display = 'none';
	}catch(E){}
	document.location='#ContactFormShowroomLink';
}

function ShowUserExplainLogin(){		
	document.getElementById("ContactFormShowroom").style.display = 'none';
	document.getElementById("UserExplainLogin").style.display = '';
	document.getElementById("loginTable").style.display = '';	
	document.location='#UserExplainLoginLink';
}

function addBookmark(title,url){
	if (window.sidebar){
			window.sidebar.addPanel(title, url,"");
		}else if( document.all){
			window.external.AddFavorite( url, title);
		}else if( window.opera && window.print ){
	return true;
	}
}

function ShowEmailForm(howform){
	if (rightpagetable.style.display ==''){
		rightpagetable.style.display = 'none';
	}else{
		rightpagetable.style.display = '';
	}
}

function displayCityLayer(displayRow,allRowsCount,theName){
	for (var i=0 ; i<allRowsCount ; i++){
		try{
			if (document.getElementById('viewCityRow'+i) != document.getElementById(displayRow)){
				document.getElementById('viewCityRow'+i).style.display = 'none'
				document.getElementById('viewCityBTN'+i).value = 'View Cities'
			}
		}catch(E){}
	}

	if (document.getElementById(displayRow).style.display == ''){
		document.getElementById(displayRow).style.display = 'none'
		document.getElementById(theName).value = 'View Cities'
	}else{
		document.getElementById(displayRow).style.display = ''
		document.getElementById(theName).value = 'Hide Cities'
	}
}

function validate_CountryForm(NForm){
	if ((NForm.CountryEN.value == "") || (NForm.CountryAR.value == "")){
		alert("Both Arabic & English country names must be entered to add a new country to the website.")
		return false;
	}
	return true;
}

function validate_CityForm(NForm){
	if ((NForm.CityEN.value == "") || (NForm.CityAR.value == "")){
		alert("Both Arabic & English city names must be entered to add a new city to the website.")
		return false;
	}
	return true;
}

function saveCookie(username,Password){
	var UsernameCookie = username;
	var PasswordCookie = Password;
	setCookie("Zammoor_Login_Remember", 1, 1000);
	setCookie("Zammoor_Login_Username", UsernameCookie, 1000);
	setCookie("Zammoor_Login_Password", PasswordCookie, 1000);
}

function setCookie(NameOfCookie, value, expiredays){
        var ExpireDate = new Date(); 
        var NumOfMonth = 6;
        ExpireDate.setMonth(ExpireDate.getMonth() + NumOfMonth);
        document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
} 

function delete_cookie(cookie_name){
	var cookie_date = new Date();
	cookie_date.setTime(cookie_date.getTime() - 1);
	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}