var hr = escape(window.location.href);
var popups = new Array();

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_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_findObj(n, d) { //v4.0
	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 && document.getElementById) x=document.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 addbookmark()
{
bookmarkurl="http://www.dubairentaldeals.com"
bookmarktitle="Welcome To Dubai Rental Deals"
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function Popup(url,width,height,target,status){
	if(!target) target = '_blank';
	if(!width)  width  = '430';
	if(!height) height = '250';
	if(!status) status = 'no';

	popups[popups.lenght] = window.open(
		url,
		target,
		"width="+width+", height="+height+", scrollbars=yes, status="+status+", resizable=yes"
	);
}
function Replay(id,url){
document.getElementById(id).src=url;
}


function submit_tell_friend(form, type, templ){
	real_action = '/tell_friend.php'
	target="_tell_friend"
	if (type != 3){
		email = form.friendsemail.value
		arr = email.match("^[0-9a-zA-Z]([0-9a-zA-Z\._\-]*)@(([0-9a-zA-Z\-]+\.)+)([0-9a-zA-Z\-]+)$")
	
		if (!arr){
			alert("Please enter valid email")
			return
		}
	}
	
	if (type == 2){
		window.open(real_action + "?type=2&friend_email=" + escape(email), target, "width=580, height=400, location=0, menubar=0, status=0, resizable=1");
	}else if (type == 3){
		window.open(real_action + "?type=3&templ=" + escape(templ), target, "width=580, height=400, location=0, menubar=0, status=0, resizable=1");
	}else{
		window.open(real_action + "?friend_email=" + escape(email), target, "width=580, height=400, location=0, menubar=0, status=0, resizable=1");
	}
	
}

function wopen2(url){
	window.open(url, 'ww', 'width=600, height=450, location=no,resizable=yes,scrollbars=yes');
}

function wopen(url){
	window.open(url, 'ww', 'width=550, height=450, location=no,resizable=yes,scrollbars=yes');
}
function wopen3(url) {
    window.open(url, 'ww', 'width=575, height=385, location=no,resizable=yes,scrollbars=no');
}

/*function submit_wish(){
	var real_action = 'wish.php';
	var target="Thank_You";
	var wish = document.forms['wish_form'].wish.value;
	var url = document.forms['wish_form'].url.value;
	if( wish.length < 1  ){
		alert("Enter subject you can not find, please !");
	}else if( url.length < 1){
		alert("Enter url of a sample site, please !");
	}else{
		window.open( real_action+"?wish="+escape(wish)+"&url="+escape(url)+"&wish_type=<?=(isset($wish_type) ? $wish_type : "1")?>", target, "location=0, menubar=0, status=0, resizable=1" );
	}
}*/



 
 // CHECK FOR DATE DIFFERENCE
function diff(D1,D2)
{
 D1Arr=D1.split('-');
 D2Arr=D2.split('-');
 d1=new Date(D1Arr[2],D1Arr[1]-1,D1Arr[0])
 d2=new Date(D2Arr[2],D2Arr[1]-1,D2Arr[0])
 if ( (d2.getTime() -d1.getTime())/(1000*3600*24) < 0 ){
  
   return false
 }
 return true
}
 
function emailCheck (emailStr) {

var emailPat=/^(.+)@(.+)$/

var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

var validChars="\[^\\s" + specialChars + "\]"

var quotedUser="(\"[^\"]*\")"

var ipDomainPat=/^\[(\d)\.(\d)\.(\d)\.(\d)\]$/

var atom=validChars + '+'

var word="(" + atom + "|" + quotedUser + ")"

var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")



var matchArray=emailStr.match(emailPat)

if (matchArray==null) {

   alert("Email address seems incorrect (check @ and .'s)")

   return false

}

var user=matchArray[1]

var domain=matchArray[2]



if (user.match(userPat)==null) {

    alert("The username doesn't seem to be valid.")

    return false

}

var IPArray=domain.match(ipDomainPat)

if (IPArray!=null) {

     for (var i=1;i<=4;i++) {

       if (IPArray[i]>255) {

           alert("Destination IP address is invalid!")

      return false

       }

    }

    return true

}



var domainArray=domain.match(domainPat)

if (domainArray==null) {

   alert("The domain name doesn't seem to be valid.")

    return false

}

var atomPat=new RegExp(atom,"g")

var domArr=domain.match(atomPat)

var len=domArr.length

if (domArr[domArr.length-1].length<2 ||

    domArr[domArr.length-1].length>3) {

   alert("The address must end in a three-letter domain, or two letter country.")

   return false

}



if (len<2) {

   var errStr="This address is missing a hostname!"

   alert(errStr)

   return false

}



return true;

}


function validi(tt)
{
 
	

 	 if((document.all('name').value) == "" )
		 {
				alert('Please enter the Name');
				document.all('name').focus();
				return false;
		 }

		 if((document.all('contact1').value) == "" )
		 {
				alert('Please enter the contact number');
				document.all('contact1').focus();
				return false;
		 }


		 if((document.all('email').value) == "" )
		 {
				alert('Please enter the email address');
				document.all('email').focus();
				return false;
		 }


		if((document.all('email').value) != "" )
		 {
			 if(!emailCheck(document.all('email').value))
			 {
			     document.all('email').focus();
				 return false;
			 }
		}
		
			 if((document.all.fromdate.value) == "" )
		 {
			 
				alert('Please enter the date');
				document.all.fromdate.focus();
				return false;
		 }

		 if((document.all.todate.value) == "" )
		 {
				alert('Please enter the date');
				document.all.todate.focus();
				return false;
		 }


		if(!diff(document.all.todaydt.value,tt.fromdate.value))
			 {
			  alert( "From date is less than today's date");
				document.all.fromdate.value = "";
				document.all.fromdate.focus();
				return false;
			 }


        if(!diff(document.all.fromdate.value,tt.todate.value))
			 {
			  alert( 'To date is less than From date');
				document.all.todate.value = "";
				document.all.todate.focus();
				return false;
			 }
//document.enquiry.submit();
if (document.all.credit.style.display=="block")
{



	    	if(document.all.cardtype.value=="")
           {
             alert("Please enter Credit Card Type");
             document.all.cardtype.focus();
              return false;
            
           }
		    	if(document.all.cardno.value=="")
           {
             alert("Please enter Credit Card Number");
             document.all.cardno.focus();
             return false;
           } 
		   if(document.all.cardno.value!="")
           {
			   if (isNaN(document.all.cardno.value))
				{
							alert('Please enter only numerical values for CC Card #.');
							document.all.cardno.value = "";
							document.all.cardno.focus();
							  return false;
				}		
			}
		    	if(document.all.expdate.value=="")
           {
             alert("Please enter Expiration Date");
             document.all.expdate.focus();
             return false;
           } 
		    if(document.all.cardno.value!="")
           {
				if(document.all.expyear.value=="")
			   {
				 alert("Please enter Expiration Date");
				 document.all.expyear.focus();
				 return false;
			   }
			}   
 }

 
 }
 
 
 function show_credit()
 {
 
 document.all.credit.style.display="block";
  document.all.wire.style.display="none";
 }
 function show_wire()
 {
 
	document.all.wire.style.display="block";
	document.all.credit.style.display="none";
	document.all.cardtype.value="";
	document.all.cardno.value="";
	document.all.cvvno.value="";
	document.all.expdate.value="";
	document.all.expyear.value="";
	document.all.sfile.value="";
 }