function displayNewUpdateRow(displayRow,hideRow){
	try{
		document.getElementById(displayRow).style.display = ''
	}catch(E){}	
	try{
		document.getElementById(hideRow).style.display = 'none'
	}catch(E){}
}

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 Properties"}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 Properties"
	}else{
		document.getElementById(displayRow).style.display = ''
		document.getElementById(theName.name).value = "Hide Properties"
	}
}

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'
		document.getElementById(theName.name).value = "View Users"
	}else{
		document.getElementById(displayRow).style.display = ''
		document.getElementById(theName.name).value = "Hide Users"
	}
}

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 displayNeighboorHoodLayer(displayRow,allRowsCount,theName){
	for (var i=0 ; i<allRowsCount ; i++){
		try{
			if (document.getElementById('updateNeighRow'+i) != document.getElementById(displayRow)){
				document.getElementById('updateNeighRow'+i).style.display = 'none'
				
			}
		}catch(E){}
	}
	if (theName.value == "View Neighborhoods")
		document.getElementById(theName.name).value = 'Hide Neighborhoods'
	else
		document.getElementById(theName.name).value = 'View Neighborhoods'

	if (document.getElementById(displayRow).style.display == ''){
		document.getElementById(displayRow).style.display = 'none'
	}else{
		document.getElementById(displayRow).style.display = ''
	}
}

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 validate_delete(NForm){
	if (window.confirm("Are you sure you want to delete this?")){
		NForm.submit();
	}
	return false;
}

function validate_MakesForm(NForm){
	if (NForm.typeEn.value == "" || NForm.typeAr.value == ""){
		alert("All Fields are Required")
		return false;
	}
	return true;
}

function validate_CategoryForm(NForm){
	if ((NForm.categoryEN.value == "") || (NForm.categoryAR.value == "")){
		alert("All Fields are Required")
		return false;
	}
	return true;
}

function validate_CountryForm(NForm){
	if ((NForm.Country.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.City.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 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.CTCatName.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.SRName.value == "" || NForm.SRPhone.value == "" || NForm.SREmail.value == "" || NForm.cityID.value == "" || NForm.SRAddress.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 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='RealEstateSellers.asp?sellers='+seller+'&locations='+locations
	document.getElementById("sellers").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.country.value == "" || NForm.categoryID.value == ""){
		alert("Fill All required fields")
		return false;
	}
}

function validate_Listshowroom(NForm){
	if (NForm.FullName.value == "" || NForm.telephone.value == "" || NForm.email.value == "" || NForm.ShowroomName.value == "" || NForm.NHoodID.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 = '';
	document.getElementById('addCar').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 dalala_start_show(){
	// Time is in seconds X 1000
	setInterval("dalala_slideshow()", 10000);
}
 
function dalala_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));
}
//========================================================================================


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 hideSomething(elementID)	{
	document.getElementById(elementID).style.display='none'
}
function showSomething(elementID)	{
	document.getElementById(elementID).style.display=''
}

function loadCity(countryID,cityID,pageName,isAll,noArabic,isNHoodID,AddOther){
	citiesFrame.location='/'+pageName+'?countryID='+countryID.value+'&cityID='+cityID+'&isAll='+isAll+'&noArabic='+noArabic+'&isNHoodID='+isNHoodID+'&AddOther='+AddOther
	top.document.getElementById("cityID").value=""
	top.document.getElementById("nHoodID").value=""
}

function loadOnlyCity(countryID,cityID){
	citiesFrame.location='/citiesFrame.asp?countryID='+countryID.value+'&cityID='+cityID
	parent.document.getElementById("cityID").value=""
}

function loadNHood(cityID,nHoodID,pageName,isAll,noArabic,isNHoodID,AddOther){
	NHoodFrame.location='/'+pageName+'?cityID='+cityID+'&nHoodID='+nHoodID+'&isAll='+isAll+'&noArabic='+noArabic+'&isNHoodID='+isNHoodID+'&AddOther='+AddOther
	top.document.getElementById("nHoodID").value=""
}

function loadCityMultipleForm(countryID,cityID,frameName,formName,isAll,noArabic,isNHoodID){
	document.getElementById(frameName).src='/cities.asp?countryID='+countryID.value+'&cityID='+cityID+'&formName='+formName+'&isAll='+isAll+'&noArabic='+noArabic+'&isNHoodID='+isNHoodID
	document.getElementById(formName).cityID.value=""
}

function loadOnlyCityMultiple(countryID,cityID,formName,frameName){
	document.getElementById(frameName).src='/citiesFrame.asp?countryID='+countryID.value+'&cityID='+cityID+'&formName='+formName
	document.getElementById(formName).cityID.value=""
}

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 loadCityMultipleForm1(countryID,cityID,frameName,formName){
	document.getElementById(frameName).src='/cities.asp?countryID='+countryID.value+'&cityID='+cityID+'&formName='+formName
	document.getElementById(formName).cityID.value=""
}

function loadCityMultipleFormContactForm(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 validate_RSSForm(NForm){
	if (NForm.AutoNewsEN.value == "" || NForm.AutoEventsEN.value == "" || NForm.AutoReviewsEN.value == ""){
		alert("All Fields are Required")
		return false;
	}
}

function validate_RealEstateRequest(NForm){
	if (NForm.makeID.value == "" || (NForm.makeID.value == "othersMake" && NForm.otherMake.value == "")){
		alert("Property type is required")
		return false;
	}
	if (NForm.NHoodID.value == "" && NForm.otherAddress.value == ""){
		alert("Address is required")
		return false;
	}
	return true;
}

function saveCookie(username,Password){
	var UsernameCookie = username;
	var PasswordCookie = Password;
	setCookie("Dalala_Login_Remember", 1, 1000);
	setCookie("Dalala_Login_Username", UsernameCookie, 1000);
	setCookie("Dalala_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();
}

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  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;
}
