var maxheigth = 240;

var loading_msg = "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td width='100%' align='center' class='expandfieldnamesright' style='padding-top:110px;'>Loading...<td></tr></table>";

function correctPostalCodeSyntax(){
   var str = document.getElementById('zip').value;
   str = str.replace(/^([a-z][0-9][a-z])[\- ]?([0-9][a-z][0-9])$/, "$1 $2");
   document.getElementById('zip').value = str;
}

function validate_email(email) {
//   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var reg = /^[a-z0-9][a-z0-9.\-]*[a-z0-9]*@[a-z0-9][a-z0-9.\-]*[a-z0-9][.][a-z]{2,4}$/;
   if(reg.test(email) == false) {
      return false;
   }else{
      return true;
   }
}

function contactformsubmit(){
        var emailto = trim(document.forms['contactform'].emailto.value);
        var content = trim(document.forms['contactform'].content.value);
		var firstname= trim(document.forms['contactform'].firstname.value);
		var lastname = trim(document.forms['contactform'].lastname.value);
		var emailfrom = trim(document.forms['contactform'].emailfrom.value);

        var valid = true;
		var msg = '';      
		if(emailto==''){
		   document.forms['contactform'].emailto.style.borderColor = '#ff0000';
		   valid = false;
		   msg += 'Invalid email to!<br>';
		}else{
		   document.forms['contactform'].emailto.style.borderColor = '#847D63';
		}		

		if(content=='' || content=='Type your message here, maximum 200 characters.'){
		   document.forms['contactform'].content.style.borderColor = '#ff0000';
		   valid = false;
		   msg += 'Invalid content!<br>';
		}else{
		   document.forms['contactform'].content.style.borderColor = '#847D63';
		}
/*
		if(firstname==''){
		   document.forms['contactform'].firstname.style.borderColor = '#ff0000';
		   valid = false;
		   msg += 'Invalid first name!<br>';
		}else{
		   document.forms['contactform'].firstname.style.borderColor = '#847D63';
		}

		if(lastname==''){
		   document.forms['contactform'].lastname.style.borderColor = '#ff0000';
		   valid = false;
		   msg += 'Invalid last name!<br>';
		}else{
		   document.forms['contactform'].lastname.style.borderColor = '#847D63';
		}
*/
		if(emailfrom=='' || !validate_email(emailfrom)){
		   document.forms['contactform'].emailfrom.style.borderColor = '#ff0000';
		   valid = false;
		   msg += 'Invalid email address!<br>';
		}else{
		   document.forms['contactform'].emailfrom.style.borderColor = '#847D63';
		}

		if(!valid){
		   modal('Error:',msg,'ok','emailtoid');
		}else{
           document.forms['contactform'].submit();
		}

}

function updatecontent(task){

 

   var formData=document.forms['filterform'];

   var formElements = formData.elements.length;

   var param = '';



   var start = formData.elements['start'].value;

   var perpage = formData.elements['perpage'].value;

   if(task=='nextpage'){

       formData.elements['start'].value = start*1 + perpage*1;

   }else if(task=='prevpage'){

       formData.elements['start'].value = start*1 - perpage*1;

   }

  

  for(count=0; count<formElements; count=count+1){

     param = param + formData.elements[count].name + '=' + formData.elements[count].value + '&';

  }   

  param = param + 'task=' + task;

  ajax_refresh_content(param);

}



function expand_dealer(id,vid){

        var tdhid = 'tdh'+id;  

//		document.getElementById(tdhid).innerHTML = wrap_ajax_response('dealer info');



	    http_request = new sendhttprequest();

        http_request.onreadystatechange = function() {

				if (http_request.readyState == 4) { 

					if (http_request.status == 200) {

						var st = http_request.responseText;

						document.getElementById(tdhid).innerHTML = wrap_ajax_response(st);

					} else {

						document.getElementById(tdhid).innerHTML = wrap_ajax_response(loading_msg);

					}

                }else{

						document.getElementById(tdhid).innerHTML = wrap_ajax_response(loading_msg);

				}			

		};



		param = 'task=dealer_details&vid='+vid+'&tdid='+id;

        http_request.open('POST', 'ajax.php', true);

        http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        http_request.send(param);

}



function detail_content(id,vid,menu){

        var tdhid = 'tdh'+id;

		var tdid = 'td'+id;

	    http_request = new sendhttprequest();

        http_request.onreadystatechange = function() {

				if (http_request.readyState == 4) { 

					if (http_request.status == 200) {

						var st = http_request.responseText;

						if(menu){

						   var menu_detail = st.split(":::SEPRATE:::");

						   document.getElementById(tdid).innerHTML = menu_detail[0] + document.getElementById(tdid).innerHTML;

						   st = menu_detail[1];

						}

						// <div style='position:relative; display = block; background-color: #000000; border: 0px solid #847C67; z-index:1; height:300px; left: 0px; top: 0px; right: 0px;'>

						document.getElementById(tdhid).innerHTML = wrap_ajax_response(st);

						// "<table height='10' width='100%' cellspacing='0' cellpadding='0' border='0' bgcolor='#F7F5EF'><tr><td align='right'><table cellspacing='0' cellpadding='0'><tr><td><img src='images/menu_end.gif'></td><td background='images/menu_back.gif'><a href='javascript:;' onclick='expand_detail(\""+tdhid+"\",0,"+vid+")' class='whitelink'>Details</a></td><td><img src='images/menu_delimiter.gif'></td><td background='images/menu_back.gif'><a href='javascript:;' onclick='expand_photos(\""+tdhid+"\",0,"+vid+");' class='whitelink'>Photos</a></td><td><img src='images/menu_delimiter.gif'></td><td background='images/menu_back.gif'><a href='#' class='whitelink'>Map</a></td><td><img src='images/menu_start.gif'></td></tr></table></td></tr></table><table style='border: 1px solid #C5C1B8;' height='"+maxheigth+"' width='100%' cellspacing='1' cellpadding='0' border='0' bgcolor='#FEFDFA'><tr><td width='100%' valign='top'>"+st+"<td></tr></table>";

					} else {

						document.getElementById(tdhid).innerHTML = wrap_ajax_response(loading_msg);

					}

                }else{

						document.getElementById(tdhid).innerHTML = wrap_ajax_response(loading_msg);

				}			

		};



		param = 'task=details&vid='+vid+'&tdid='+id+'&menu='+menu;

        http_request.open('POST', 'ajax.php', true);

        http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        http_request.send(param);

}



function expand_detail(id,h,vid){

        var tdid = 'td'+id;

        document.getElementById('viewdetails'+id).innerHTML = '<a href="javascript:;" onClick="colapse_detail('+id+','+vid+');" class="contentlink">Close Details&nbsp;<img src="/images/colapse.gif" border="0"></a>';

	    if(h<200){

			    h=h+25;		

				document.getElementById(tdid).style.height = h+'px';
				setTimeout("expand_detail('"+id+"',"+h+","+vid+")",50);

		}else{

                var elem = document.createElement('div');

				var tdhid = 'tdh'+id;

				elem.setAttribute('id',tdhid);

				document.getElementById(tdid).appendChild(elem);

				detail_content(id,vid,1);

		}

}



function colapse_detail(id,vid){

       var tdhid = 'tdh'+id;

	   var tdid = 'td'+id;

	   document.getElementById(tdid).innerHTML = '';

	   while(parseInt(document.getElementById(tdid).style.height) > 0){

    	   document.getElementById(tdid).style.height = (parseInt(document.getElementById(tdid).style.height) - 1)+'px';

	   }

	   document.getElementById('viewdetails'+id).innerHTML = '<a href="javascript:;" onClick="expand_detail('+id+',0,'+vid+');" class="contentlink">View Details&nbsp;<img src="/images/expand.gif" border="0"></a>';

}



function expand_contact(id,h,vid,phone){

        var tdhid = 'tdh'+id;

        var st = "<form action='javascript:;' name='contact_form_"+vid+"' style='margin:7px;'><table width='100%' cellpadding='0' cellspacing='0' border='0'>";

		    st += "<tr><td colspan='4' class='expandfieldnames'><b>Call Seller:</b></td></tr>";

		    st += "<tr><td width='100' class='expandfieldnames2'>Phone:</td><td colspan='3' class='phone'><b>"+phone+"</b></td></tr>";

		    st += "<tr><td colspan='4' height='5'><img src='/images/spacer.gif' height='1' width='1'></td></tr>";

		    st += "<tr><td colspan='4' class='expandfieldnames'><b>Email Seller:</b></td></tr>";

		    st += "<tr><td colspan='4' height='5'><img src='/images/spacer.gif' height='1' width='1'></td></tr>";

			st += "<tr><td valign='top' class='expandfieldnames2'>Content: </td><td colspan='3'><textarea name='content' rows='6' cols='53' class='tb_red_err' onclick='if(this.value==\"Type your message here, maximum 200 characters.\")this.value=\"\"'>Type your message here, maximum 200 characters.</textarea></td></tr>";

		    st += "<tr><td colspan='4' height='5'><img src='/images/spacer.gif' height='1' width='1'></td></tr>";

		    st += "<tr><td class='expandfieldnames2'>First Name: </td><td width='160'><input type='textbox' name='firstname' class='tb_red_err'></td><td class='expandfieldnames2'>Last Name: </td><td width='255'><input type='textbox' name='lastname' class='tb_red_err'></td>";

		    st += "<tr><td colspan='4' height='5'><img src='/images/spacer.gif' height='1' width='1'></td></tr>";

		    st += "<tr><td class='expandfieldnames2'>Your Email: </td><td width='160'><input type='textbox' name='buyer_email' class='tb_red_err'></td><td class='expandfieldnames2'>Your Contact #: </td><td><input type='textbox' name='buyer_contact' class='tb_red_err'></td>";

		    st += "<tr><td colspan='4' height='5'><img src='/images/spacer.gif' height='1' width='1'></td></tr>";

			st += "<tr><td></td><td colspan='3'><input type='submit' name='send_email' value='Send' class='signinbtn' onclick='email_seller("+vid+",\""+id+"\");'></td></tr></table></form>";      



		document.getElementById(tdhid).innerHTML = wrap_ajax_response(st);

}



function email_seller(vid,id){

        var tdhid = 'tdh'+id;

        var content = trim(document.forms['contact_form_'+vid].content.value);

		var firstname= trim(document.forms['contact_form_'+vid].firstname.value);

		var lastname = trim(document.forms['contact_form_'+vid].lastname.value);

		var buyer_email = trim(document.forms['contact_form_'+vid].buyer_email.value);

		var buyer_contact = trim(document.forms['contact_form_'+vid].buyer_contact.value);

        var valid = true;

		var msg = '';      

		if(content=='' || content=='Type your message here, maximum 200 characters.'){

		   document.forms['contact_form_'+vid].content.style.borderColor = '#ff0000';

//		   document.forms['contact_form_'+vid].content.style.background = '#FCF2D3';

		   valid = false;

		   msg += 'Your email is empty!<br>';

		}else{

		   document.forms['contact_form_'+vid].content.style.borderColor = '#847D63';

//		   document.forms['contact_form_'+vid].content.style.background = '#ffffff';

		}

		if(firstname==''){

		   document.forms['contact_form_'+vid].firstname.style.borderColor = '#ff0000';

//		   document.forms['contact_form_'+vid].firstname.style.background = '#FCF2D3';

		   valid = false;

		   msg += 'Invalid first name!<br>';

		}else{

		   document.forms['contact_form_'+vid].firstname.style.borderColor = '#847D63';

//		   document.forms['contact_form_'+vid].firstname.style.background = '#ffffff';

		}

		

		if(lastname==''){

		   document.forms['contact_form_'+vid].lastname.style.borderColor = '#ff0000';

//		   document.forms['contact_form_'+vid].lastname.style.background = '#FCF2D3';

		   valid = false;

		   msg += 'Invalid last name!<br>';

		}else{

		   document.forms['contact_form_'+vid].lastname.style.borderColor = '#847D63';

//		   document.forms['contact_form_'+vid].lastname.style.background = '#ffffff';

		}

		

		if(buyer_email=='' && buyer_contact==''){

		   document.forms['contact_form_'+vid].buyer_email.style.borderColor = '#ff0000';

//		   document.forms['contact_form_'+vid].buyer_email.style.background = '#FCF2D3';

		   document.forms['contact_form_'+vid].buyer_contact.style.borderColor = '#ff0000';

//		   document.forms['contact_form_'+vid].buyer_contact.style.background = '#FCF2D3';		   

		   valid = false;

		   msg += 'Email or contact number is required!<br>';

		}else{

		   if(buyer_email!=''){

		      var reg = /^[a-z0-9][a-z0-9.\-]*[a-z0-9]*@[a-z0-9][a-z0-9.\-]*[a-z0-9][.][a-z]{2,4}$/;

			  if(!reg.test(buyer_email)){

				   document.forms['contact_form_'+vid].buyer_email.style.borderColor = '#ff0000';

				   document.forms['contact_form_'+vid].buyer_email.style.background = '#FCF2D3';

				   valid = false;

				   msg += 'Invalid email address!<br>';

		      }else{

		           document.forms['contact_form_'+vid].buyer_email.style.borderColor = '#847D63';

		           document.forms['contact_form_'+vid].buyer_email.style.background = '#ffffff';

			  }

           }

		   

		   if(buyer_contact!=''){

		      var reg = /^[1-9][0-9][0-9](-| )?[0-9]{3}(-| )?[0-9]{4}$/;

			  if(!reg.test(buyer_contact)){

				   document.forms['contact_form_'+vid].buyer_contact.style.borderColor = '#ff0000';

				   document.forms['contact_form_'+vid].buyer_contact.style.background = '#FCF2D3';

				   valid = false;

				   msg += 'Invalid contact number!<br>';		  

			  }else{

				   document.forms['contact_form_'+vid].buyer_contact.style.borderColor = '#847D63';

				   document.forms['contact_form_'+vid].buyer_contact.style.background = '#ffffff';			  

			  }

		   }

		   

		}				



		if(!valid){

		   modal('Error:',msg,'ok');

		}else{

		   var param = 'task=send_email&vehicle_id='+vid+'&content='+content+'&firstname='+firstname+'&lastname='+lastname+'&buyer_email='+buyer_email+'&buyer_contact='+buyer_contact;

		   http_request = new sendhttprequest();

		   http_request.onreadystatechange = function() {

					if (http_request.readyState == 4) { 

						if (http_request.status == 200) {

							var st = http_request.responseText;

							 document.getElementById(tdhid).innerHTML = wrap_ajax_response(st);

						} else {

							document.getElementById(tdhid).innerHTML = wrap_ajax_response(loading_msg); 

						}

					}else{

							document.getElementById(tdhid).innerHTML = wrap_ajax_response(loading_msg); 

					}			

		   };

		   http_request.open('POST', 'ajax.php', true);

		   http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

		   http_request.send(param);

		}

}



function trim(stringToTrim) {

	return stringToTrim.replace(/^\s+|\s+$/g,"");

}





function expand_photos(id,h,vid){

        var tdhid = 'tdh'+id;

        param = 'task=detail_photos&vid='+vid;

	    http_request = new sendhttprequest();

        http_request.onreadystatechange = function() {

				if (http_request.readyState == 4) { 

					if (http_request.status == 200) {

						var st = http_request.responseText;

						document.getElementById(tdhid).innerHTML = wrap_ajax_response(st);

						//"<table height='10' width='100%' cellspacing='0' cellpadding='0' border='0' bgcolor='#F7F5EF'><tr><td align='right'><table cellspacing='0' cellpadding='0'><tr><td><img src='images/menu_end.gif'></td><td background='images/menu_back.gif'><a href='javascript:;' onclick='expand_detail(\""+tdhid+"\",0,"+vid+")' class='whitelink'>Details</a></td><td><img src='images/menu_delimiter.gif'></td><td background='images/menu_back.gif'><a href='javascript:;' onclick='expand_photos(\""+tdhid+"\",0,"+vid+");' class='whitelink'>Photos</a></td><td><img src='images/menu_delimiter.gif'></td><td background='images/menu_back.gif'><a href='#' class='whitelink'>Map</a></td><td><img src='images/menu_start.gif'></td></tr></table></td></tr></table><table style='border: 1px solid #C5C1B8;' height='"+maxheigth+"' width='100%' cellspacing='1' cellpadding='0' border='0' bgcolor='#FEFDFA'><tr><td width='100%' valign='top'>"+st+"<td></tr></table>";

					} else {

						document.getElementById(tdhid).innerHTML = wrap_ajax_response(loading_msg); 

					}

                }else{

						document.getElementById(tdhid).innerHTML = wrap_ajax_response(loading_msg); 

				}			

		};

        http_request.open('POST', 'ajax.php', true);

        http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        http_request.send(param);

		

}



function hidelargephotos(vid){

    for(var i=0; i<12; i++){

	    var id = (vid) ? 'bigphotocontainer_'+vid+'_'+i : 'bigphotocontainer_'+i;

	    if(document.getElementById(id)){

		    document.getElementById(id).style.display = 'none';

		}

	}

}

	

function sendhttprequest(){

        if (window.XMLHttpRequest) { // Mozilla, Safari,...

            http_request = new XMLHttpRequest();

            if (http_request.overrideMimeType) {

                http_request.overrideMimeType('text/xml');

                // See note below about this line

            }

        } 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('Giving up : Cannot create an XMLHTTP instance');

            return false;

        }

		return http_request;

}







function ajax_refresh_content(param){

	    http_request = new sendhttprequest();

        http_request.onreadystatechange = function() {

				if (http_request.readyState == 4) { 

					if (http_request.status == 200) {

						var st = http_request.responseText;

						document.getElementById('content').innerHTML = st;

					} else {

						document.getElementById('content').innerHTML = "Loading ....";

					}

                }else{

						document.getElementById('content').innerHTML = "Loading ....";

				}			

		};

        http_request.open('POST', 'ajax.php', true);

        http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        http_request.send(param);

}



function wrap_ajax_response(st){

        //var tdhid = 'tdh'+id;

		/*

		var menu = 	"<table height='10' width='100%' cellspacing='0' cellpadding='0' border='0' bgcolor='#F7F5EF'><tr><td align='right'>";

		   menu +=  "<table cellspacing='0' cellpadding='0'><tr><td><img src='images/menu_end.gif'></td><td background='images/menu_back.gif'>";

		   menu +=  "<a href='javascript:;' onclick='expand_detail(\""+id+"\",0,"+vid+");' class='whitelink'>Details</a>";

		   menu +=  "</td><td><img src='images/menu_delimiter.gif'></td><td background='images/menu_back.gif'>";

		   menu +=  "<a href='javascript:;' onclick='expand_photos(\""+id+"\",0,"+vid+");' class='whitelink'>Photos</a>";

		   menu +=  "</td><td><img src='images/menu_delimiter.gif'></td><td background='images/menu_back.gif'>";

		   menu +=  "<a href='javascript:;' onclick='expand_contact(\""+id+"\",0,"+vid+");' class='whitelink'>Contact</a>";

		   menu +=  "</td><td><img src='images/menu_start.gif'></td></tr></table>";

		   menu +=  "</td></tr></table>";

		   */

		   

		   var menu =  "<table style='border: 1px solid #C5C1B8;' height='"+maxheigth+"' width='100%' cellspacing='1' cellpadding='0' border='0' bgcolor='#FEFDFA'>";

		   menu +=  "<tr><td width='100%' valign='top'>"+st+"<td></tr></table>";

		   return menu;

}





function modal(title,msg,button,idtohide){

   if(document.getElementById(idtohide)){

	  document.getElementById(idtohide).style.visibility = 'hidden';

   }

   if(!document.getElementById('modalid')){

      var modaldiv = document.createElement('div');

      document.body.appendChild(modaldiv);	  

      modaldiv.id = 'modalid'; 

      modaldiv.className = 'opaque';

      document.getElementById('modalid').style.width = getWinX()-22 +'px';

   }

   document.getElementById('modalid').style.height =  (document.body.scrollHeight>getWinY()) ? (document.body.scrollHeight)+'px' : getWinY()-5+'px'; 

   document.getElementById('modalid').style.display = 'block';



   if(!document.getElementById('modalid2')){

      var modaldiv2 = document.createElement('div');

      modaldiv2.id = 'modalid2'; 

      modaldiv2.className = 'opaque2';

      document.body.appendChild(modaldiv2);

   }

   document.getElementById('modalid2').style.display = 'block';

//   document.getElementById('modalid2').style.width = '360px';

//   document.getElementById('modalid2').style.height = '240px';

   document.getElementById('modalid2').style.top = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + 240/2 +'px'; /* getWinY()/2 - 240/2; */

   document.getElementById('modalid2').style.left = getWinX()/2 - 360/2 +'px';


   var cont = '<div style="border: thin solid #787D8D; height:240px; width:360px;">';
   cont += '<table width="100%" bgcolor="#ffffff" background="red">';
   cont += '<tr><td height="40" bgcolor="#787D8D" style="padding:5px;color:#ffffff;font-weight:bold;">'+title+'</td></tr>';
   cont += '<tr><td align="center" height="154" style="padding:0 20px 0 20px;"><p>'+msg+'</p></td></tr>';
   cont += '<tr><td align="center" style="padding-bottom:8px;">';
   
   if(button!='none') 
   cont += '<input type="button" name="button" value="'+button+'" class="signinbtn" onclick="close_modal(\''+idtohide+'\');">';

   cont += '</td></tr></table></div>';
   document.getElementById('modalid2').innerHTML = cont;
   
//   document.getElementById('modalid2').innerHTML = '<table width="100%" bgcolor="#000000" cellpadding="1" cellspacing="0"><tr><td height="230" valign="top"><table width="100%" bgcolor="#ffffff"><tr><td height="40" bgcolor="#787D8D" style="padding:5px;color:#ffffff;font-weight:bold;">'+title+'</td></tr><tr><td align="center" height="154"><p>'+msg+'</p></td></tr><tr><td align="center" style="padding-bottom:8px;"><input type="button" name="button" value="'+button+'" class="signinbtn" onclick="close_modal(\''+idtohide+'\');"></td></tr></table></td></tr></table>';

}



function close_modal(idtohide){

  if(document.getElementById(idtohide)){ document.getElementById(idtohide).style.visibility = 'visible'; }

  document.getElementById('modalid').style.display = 'none';

  document.getElementById('modalid2').style.display = 'none';  

}



function cfgbox(title,msg,url){

   if(!document.getElementById('modalid')){

      var modaldiv = document.createElement('div');

      document.body.appendChild(modaldiv);	  

      modaldiv.id = 'modalid'; 

      modaldiv.className = 'opaque';

      document.getElementById('modalid').style.width = '100%';

   }

   document.getElementById('modalid').style.height = document.body.scrollHeight;

   document.getElementById('modalid').style.display = 'block';



   if(!document.getElementById('modalid2')){

      var modaldiv2 = document.createElement('div');

      modaldiv2.id = 'modalid2'; 

      modaldiv2.className = 'opaque2';

      document.body.appendChild(modaldiv2);

   }

   document.getElementById('modalid2').style.display = 'block';

   document.getElementById('modalid2').style.width = '360px';

   document.getElementById('modalid2').style.height = '240px';

   document.getElementById('modalid2').style.top = document.body.scrollTop + 240/2; /* getWinY()/2 - 240/2; */

   document.getElementById('modalid2').style.left = getWinX()/2 - 360/2;



   document.getElementById('modalid2').innerHTML = '<table width="100%" bgcolor="#000000" cellpadding="1" cellspacing="0"><tr><td height="226" valign="top"><table border="0" width="100%" bgcolor="#ffffff"><tr><td height="40" bgcolor="#787D8D" style="padding:5px;color:#ffffff;font-weight:bold;">'+title+'</td></tr><tr><td align="center" height="155"><p>'+msg+'</p></td></tr><tr><td align="center" style="padding-bottom:10px;"><input type="button" name="button" value="Ok" class="signinbtn" onclick="close_modal();document.location=\''+url+'\'">&nbsp;&nbsp;<input type="button" name="button" value="Cancel" class="signinbtn" onclick="close_modal();"></td></tr></table></td></tr></table>';

}



function getWinX(){

var winW = 630;



if (parseInt(navigator.appVersion)>3) {

 if (navigator.appName=="Netscape") {

  winW = window.innerWidth;

 }

 if (navigator.appName.indexOf("Microsoft")!=-1) {

  winW = document.body.offsetWidth;

 }

}

return winW;

}



function getWinY(){

var winH = 460;



if (parseInt(navigator.appVersion)>3) {

 if (navigator.appName=="Netscape") {

  winH = window.innerHeight;

 }

 if (navigator.appName.indexOf("Microsoft")!=-1) {

  winH = document.body.offsetHeight;

 }

}

return winH;

}



function set_state(state){

  if(document.getElementById('state')){

	  if(state=='US') document.getElementById('state').innerHTML = document.getElementById('usstates').innerHTML;

	  else if(state=='CA') document.getElementById('state').innerHTML = document.getElementById('castates').innerHTML;

	  else { document.getElementById('state').innerHTML = "<select name=\"state\"><option value=\"\" selected>Choose a State</option></select>"; }

  }

}







// right column JS

					function addtowishlist(vid,make,model,year){

						url = "ajax.php";

						id = "whishlist";

						param = "vid="+vid+"&makename="+make+"&modelname="+model+"&year="+year+"&task=addtowishlist";

						http_request = new sendhttprequest();

						http_request.onreadystatechange = function() {

									if (http_request.readyState == 4) { 

										if (http_request.status == 200) {

											var st = trim(http_request.responseText);

//											alert(st);

											if (st == "ALREADY_IN_WISH_LIST"){ modal('Warning:','This item is already in your wish list!','ok'); }

											else if(st.length > 0){ addtdtowishlist(vid,st);}

										}

									}

						};

						http_request.open('POST', url, true);

						http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

						http_request.send(param);

					}	

				    function addtdtowishlist(vid,st){

						var theTable = document.getElementById('tableId');

						var txt = document.createTextNode('');

						var td = document.createElement('td');

						var tr = document.createElement('tr');

						td.appendChild(txt);

						tr.appendChild(td);



//						if(theTable.firstChild)

     //theTable.tBodies[0].firstChild.innerHTML = "<td></td>";

						   theTable.tBodies[0].insertBefore(tr,theTable.tBodies[0].firstChild);

//						else

//						   theTable.tBodies[0].insertBefore(tr);

				        //	theTable.tBodies[0].appendChild(tr);

						myid = "wish"+vid;

						td.setAttribute("id", myid);

//						td.style.background = "#DBD9C1";

						td.className = 'wishlist';

						increaseheight(0,myid,st);

						

						for(i=0;i<theTable.tBodies[0].rows.length;i++){

						   if(i>5){

						         theTable.tBodies[0].removeChild(theTable.tBodies[0].rows[i]);

/*								 if(!document.getElementById('wishlistmore')){

									 txt = document.createTextNode('more...');

									 td = document.createElement('td');

									 tr = document.createElement('tr');

									 td.appendChild(txt);

									 tr.appendChild(td);

									 td.setAttribute("id", "wishlistmore");

									 td.className = 'wishlist';

									 theTable.tBodies[0].appendChild(tr);

						         } */

						   }

						}

						

						if(document.getElementById('wishlistviewall')) document.getElementById('wishlistviewall').innerHTML = "<a href='wishlist.php' class='boxeditlink'>View All</a>";

					}

					function increaseheight(h,myid,st){

 					    if(h < 16){

					        h = h + 2;

    					    document.getElementById(myid).style.height = h;

							setTimeout("increaseheight("+h+",'"+myid+"','"+st+"')",1);

					    }else{

							document.getElementById(myid).innerHTML = st;

						}

					

					}

		            function winloc(url){
					   window.location.href = 'http://www.yahoo.com';
					}
