var xmlhttp=false;

if (!xmlhttp) {
	if (window.XMLHttpRequest) { 
		xmlhttp=new XMLHttpRequest(); 
		} else {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	if (!xmlhttp) {
	alert("Your browser doesn't support AJAX.");
	}
}



function validate_required(field,alerttxt)
{
	with (field){
		if (value==null||value==""){
  			var error_div = document.getElementById("error_message");
  			error_div.innerHTML=alerttxt;
  			return false;
		}
		else {return true}
	}
}

function validate_required1(field,alerttxt)
{
	with (field){
		if (value==null||value==""){
  			var r=confirm(alerttxt);
			if (r==true) {
  				field.focus();
  			}
  			return false;
		}
		else {return true}
	}
}


function validate_email(email){
	 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	 return reg.test(email);
}

function validate_contact_form(thisform)
{
with (thisform)
{
	document.getElementById("error_message").style.display="none;";
	if (validate_required(name,"Please fill out Full Name!")==false)
  		{name.focus();return false;}
	if (validate_required(email,"Please fill out Email Address!")==false)
  		{email.focus();return false;}
  	if(validate_email(email.value) == false)
  		{ email.focus(); 
  		var error_div = document.getElementById("error_message");
  		error_div.innerHTML="Invalid Email!";
  		return false;
  		}	
	if (validate_required(phone,"Please fill out Phone Number!")==false)
  		{phone.focus();return false;}
  	if (validate_required(type_of_shoot,"Please select Type of Shoot!")==false)
  		{type_of_shoot.focus();return false;}
	if (validate_required(location,"Please fill out Venue & Location!")==false)
  		{location.focus();return false;}
	if (validate_required(ref_by,"Please fill out Referred By!")==false)
  		{ref_by.focus();return false;}
	if (validate_required(message,"Please fill out Message!")==false)
  		{message.focus();return false;}  	
  		
    if(!xmlhttp )
    {
        alert("Your browser does not support ajax");
        return;
    }   
    
    var params = "name="+name.value+"&email="+email.value+"&phone="+phone.value+"&type_of_shoot="+type_of_shoot.value+"&month="+month.value+"&day="+day.value+"&year="+year.value+"&location="+location.value+"&ref_by="+ref_by.value+"&message="+message.value;
    
    //var params = "fname="+fname.value;
    
    xmlhttp.open("POST", "http://malomanblog.com/email.php" , true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length",params.length);
    xmlhttp.setRequestHeader("Connection","close");
    
    xmlhttp.onreadystatechange = function (){
		 	   if (xmlhttp.readyState==4){ 
		 	   		//
    		   		if (xmlhttp.responseText=="true") {
    		   			//alert(xmlhttp.responseText);
    		   			var error_div = document.getElementById("error_message");
  					error_div.innerHTML="Thank you, your email has been sent";
  					name.value=""; email.value=""; phone.value=""; type_of_shoot.value=""; location.value=""; ref_by.value=""; message.value="";
  					document.getElementById("wedding_date_name").style.display="none";
  					document.getElementById("wedding_date").style.display="none";
    		   		}
					else{
						alert("Error Sending mail");
					}
				}
	};
    xmlhttp.send(params);	
}
return false;
}

function validate_contact_form1(thisform)
{
with (thisform)
{
	if (validate_required1(name,"Please fill out Full Name")==false)
  		{return false;}
	if (validate_required1(email,"Please fill out Email Address")==false)
  		{return false;}
  	if(validate_email(email.value) == false)
  		{
  		var r=confirm("Invalid Email");
		if (r==true) {
  			email.focus();
  		}
  		return false;
  		}	
	if (validate_required1(phone,"Please fill out Phone Number")==false)
  		{return false;}
  	if (validate_required1(type_of_shoot,"Please select Type of Shoot")==false)
  		{return false;}
	if (validate_required1(location,"Please fill out Venue & Location")==false)
  		{return false;}
	if (validate_required1(ref_by,"Please fill out Referred By")==false)
  		{return false;}
	if (validate_required1(message,"Please fill out Message")==false)
  		{return false;}  	
  		
    if(!xmlhttp )
    {
        alert("Your browser does not support ajax");
        return;
    }   
    
    var params = "name="+name.value+"&email="+email.value+"&phone="+phone.value+"&type_of_shoot="+type_of_shoot.value+"&month="+month.value+"&day="+day.value+"&year="+year.value+"&location="+location.value+"&ref_by="+ref_by.value+"&message="+message.value;
    
    //var params = "fname="+fname.value;
    
    xmlhttp.open("POST", "http://malomanblog.com/email.php" , true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length",params.length);
    xmlhttp.setRequestHeader("Connection","close");
    
    xmlhttp.onreadystatechange = function (){
		 	   if (xmlhttp.readyState==4){ 
		 	   		//
    		   		if (xmlhttp.responseText=="true") {
    		   			//alert(xmlhttp.responseText);    		   			
    		   			alert("Thank you, your email has been sent");
  					name.value=""; email.value=""; phone.value=""; type_of_shoot.value=""; location.value=""; ref_by.value=""; message.value="";
  					document.getElementById("wedding_date_name").style.display="none";
  					document.getElementById("wedding_date").style.display="none";
    		   		}
					else{
						var error_div = document.getElementById("error_message");
  						error_div.innerHTML="Error Sending mail";
					}
				}
	};
    xmlhttp.send(params);	
}
return false;
}



function chimpNewsletter(thisform){
	with (thisform)
	{
		var file="http://malomanblog.com/newsletter.php?id="+id.value+"&u="+u.value+"&MERGE0="+MERGE0.value+"&MERGE1="+MERGE1.value+"&MERGE2="+MERGE2.value+"&EMAILTYPE="+EMAILTYPE.value;
		window.open(file,"","width=800,height=520");
		return false;
	}
}

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="random"){
		LeftPosition=(screen.availWidth)?Math.floor(Math.random()*(screen.availWidth-w)):50;
		TopPosition=(screen.availHeight)?Math.floor(Math.random()*((screen.availHeight-h)-75)):50;
	}
	if(pos=="center"){
		LeftPosition=(screen.availWidth)?(screen.availWidth-w)/2:50;
		TopPosition=(screen.availHeight)?(screen.availHeight-h)/2:50;
	}
	if(pos=="default"){
		LeftPosition=50;
		TopPosition=50;
	}else{
		if((pos!="center" && pos!="random" && pos!="default") || pos==null){
			LeftPosition=0;
			TopPosition=20
		}
	}
	
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';	
	win=window.open(mypage,myname,settings);
	if(win.focus){
		win.focus();
	}
}


function MM_jumpMenu(targ,selObj,restore, cat)
{ //v3.0
  if(cat){  
    eval(targ+".location='?cat="+selObj.options[selObj.selectedIndex].value+"'");
  }else{
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  }
  if (restore) selObj.selectedIndex=0;
}


function showHideComments(postId, homeUrl)
{
	var imgElem = document.getElementById("updown_" + postId);
	var commentContent = document.getElementById("comment_content" + postId);		
	
	if(!imgElem || !commentContent) return;		
	
	if(commentContent.style.display == "block")
	{		
		commentContent.style.display = "none";
		imgElem.src = homeUrl + "/wp-content/themes/malomanblack/images/arrow_down.gif";
		imgElem.alt = "Show comments";
		imgElem.title = "Show comments";
	}else{	
		commentContent.style.display = "block";
		imgElem.src = homeUrl + "/wp-content/themes/malomanblack/images/arrow_up.gif";
		imgElem.alt = "Hide comments";
		imgElem.title = "Hide comments";
	}
		
}


function checkValues(form)
{
	var elem;			
		var errorElem;			
		
		errorElem = document.getElementById("errorText");
		
		elem = document.getElementById("author");			
		if(elem && (elem.value == "Your name" || elem.value==""))
		{
			errorElem.innerHTML = "Please enter your name & Please type a comment.";				
			return;
		}
		
		elem = document.getElementById("email");					
		if(elem && (elem.value == "Email address (will not be displayed on blog)" || elem.value==""))
		{
			errorElem.innerHTML = "Please enter an email address";							
			return;
		}
		
		if(elem && !is_email(elem.value)){
			errorElem.innerHTML = "Please enter a valid email address";							
			return;
		}
		
		
		elem = document.getElementById("comment");			
		if(elem && (elem.value == "Comments" || elem.value==""))
		{
			errorElem.innerHTML = "Please enter your name & Please type a comment.";
			return;
		}
		
		elem = document.getElementById("url");				
		if(elem &&  elem.value == "Website address"){
			document.getElementById("url").value = "";
		}
		
		document.getElementById("commentform").submit();
}

function changePic(imgElement, over)
{
	var imageName = imgElement.src;
	var pos = imageName.lastIndexOf("/");
	var path = imageName.substr(0, pos);	
	var fileName = imageName.substr(pos + 1);
	
	var splitPos = fileName.lastIndexOf("_off.gif");
	if(-1 != fileName.lastIndexOf("_off.gif")){
		var linkName = fileName.substr(0, splitPos);
		imageName = linkName + "_on.gif";
	}else{
		splitPos = fileName.lastIndexOf("_on.gif");
		var linkName = fileName.substr(0, splitPos);
		imageName = linkName + "_off.gif";
	}
	
	imgElement.src = path + "/" + imageName;
}

function copyToClipboard()
{	
}

function urlDoPopup(home, url, postTitle)
{
	var editCommentWindow=open("","","status=1,scrollbars=no,width=550,height=440");
	editCommentWindow.document.open();
	htmlcode = '<html><head><title>Link to this post</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
			
    htmlcode += '<LINK REL=StyleSheet HREF="'+home+'/wp-content/themes/peapod/popupStyle.css" TYPE="text/css" MEDIA=screen> ';
	htmlcode += '<scr' + 'ipt type="text/javascript" src="' + home + '/wp-content/themes/peapod/js/common.js" ></sc' + 'ript>';
		
	htmlcode = htmlcode + '</head><body id="popupbody" onload="javascript: document.getElementById(\'link\').focus();document.getElementById(\'link\').select();">';
	htmlcode = htmlcode + '';	
	htmlcode = htmlcode + '<div align="center">';	
	htmlcode = htmlcode +'<table width="100%"  height="80" cellpadding="0" cellspacing="0" border="0" style="background-color:#00b434;"><tr><th width="100%" height="100%" align="center" valign="middle">';
	htmlcode = htmlcode + '<div id="title">LINK TO POST</div>'
	htmlcode = htmlcode + '<div id="postTitle">' + postTitle + '</div>';	
	htmlcode = htmlcode + '</th></tr></table>';
    	htmlcode = htmlcode + '    <table width="100%" cellpadding="0" cellspacing="0" border="0">	<tr>		<th align="center" valign="top">			<table cellpadding="0" cellspacing="0" border="0">				<tr>					<th align="center"> ';
	htmlcode = htmlcode + '         <textarea class="textareaElement" name="link" id="link" cols="60" rows="2" tabindex="1" style="margin-top:40px;">'+ url +'</textarea>';		
	htmlcode = htmlcode + '         </th>				</tr>				<tr>					<th align="right">';	
	htmlcode = htmlcode + '         	<div id="buttons"> <input class="buttonElement" name="Close" type="button" id="close" tabindex="3" value="Close" onclick="javascript:window.close();"/></div>';				
	htmlcode = htmlcode + '         </th>				</tr>			</table>		</th>	</tr></table>';	
	htmlcode = htmlcode + '		</div>';
	htmlcode = htmlcode + '';
	htmlcode = htmlcode + '<div id="footer" style="text-align:center;">&nbsp;</div>';
    htmlcode = htmlcode + '</body>';
	htmlcode = htmlcode + '</html>';		

	
	editCommentWindow.document.write(htmlcode);
	editCommentWindow.document.close();
}

function is_email(email)
{	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) return true;
	else return false;
}

function imagesPreloader(homepage, theme){	
	
	initButtons();
}

function initButtons(){	
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){            	
        if(elements[i].className == "navbutton" || elements[i].className == "buttonComment"){        	
        	elements[i].onmouseover = function() {
        			if(this.className.indexOf("hover") == -1)
						this.className += "hover";
				};
        	elements[i].onmouseout = function() {
					this.className = this.className.replace("hover", "");					
				};
        }
    }    
}
