// JavaScript Document

var prox;
var proy;
var proxc;
var proyc;
var id = 'fd';


function show(event){/*--open--*/
    clearInterval(prox);
    clearInterval(proy);
    clearInterval(proxc);
    clearInterval(proyc);
//	alert(img)
    var o = document.getElementById(id);

	o.style.display = "block";
	o.style.width = "1px";
    o.style.height = "1px"; 
    prox = setInterval(function(){openx(o,450)},10);
	
	var img = '<table border=0 cellpadding=5 width="380" style="color:#000066;" align="center"><tr><td width="170" align="right" valign="middle">* Contact Name:</td><td align="left" valign="middle" width="203"><input type="text" id="full_name" name="full_name" size="24"></td></tr><tr><td width="170" align="right" valign="middle">Store Name:</font></td><td align="left" valign="middle" width="203"><input type="text" id="store_name" name="store_name" size="24"></td></tr><tr><td width="170" align="right" valign="middle">* Customer Number:</td><td align="left" valign="middle" width="203"><input type="text" id="cust_num" name="cust_num" size="24" maxlength="10"></td></tr><tr><td width="170" align="right" valign="middle">* Subject: </td><td align="left" valign="middle" width="203"><input type="text" id="subject" name="country" size="24"></td></tr><tr><td width="170" align="right" valign="middle">* Email:</td><td align="left" valign="middle" width="203"><input type="text" id="email" name="city" size="24"></td></tr><tr><td width="170" align="right" valign="middle">Telephone:</td><td align="left" valign="middle" width="203"><input type="text" id="telephone" name="telephone" size="24" maxlength="10"></td></tr><tr><td width="170" align="right" valign="middle">* Comments:</td><td align="left" valign="middle" width="203"><textarea id="comments" name="comments" cols="19" rows="4"></textarea> </td></tr><tr><td width="170" ></td><td align="left" valign="middle" width="203"><img src="images/btn_submit.jpg" style="cursor:pointer" onclick="submit_email()" onMouseover="this.src=\'images/btn_submit_over.jpg\'" onMouseout="this.src=\'images/btn_submit.jpg\'"></td></tr></table><div id="mail_msg" style="display:none; color:red; text-align:left ;padding-left: 50px ">Your comments have been send to us successfully.</div>';
	

	var tag_closee = 'Questions &amp; Inquiries <div id="clz" sytle="z-index:10000000;" onclick = "closeed();"><img src="images/close_btn.jpg" /></div>';
	var tag_contentt = '<div id="content" >' + img;
    o.innerHTML=tag_contentt+'</div>'+tag_closee;
 
	
} 



function openx(o,x){/*--openX--*/
    var cx = parseInt(o.style.width);
    if(cx < x)
	{
		o.style.width = (cx + Math.ceil((x-cx)/5)) +"px";
	}
    else
    {
		clearInterval(prox);proy = setInterval(function(){openy(o,485)},10);
    }
}
 
function openy(o,y){/*--openY--*/ 
    var cy = parseInt(o.style.height);
    if(cy < y)
    {
    o.style.height = (cy + Math.ceil((y-cy)/15)) +"px";
    }
    else
    {
    clearInterval(proy); 
    }
    } 
	
function closeed(){/*--close--*/
    clearInterval(prox);
    clearInterval(proy);
    clearInterval(proxc);
    clearInterval(proyc); 
    var o = document.getElementById(id);
    if(o.style.display == "block")
    {
    proyc = setInterval(function(){closey(o)},10); 
    } 
} 

function closey(o){/*--closeY--*/ 
    var cy = parseInt(o.style.height);
	if (cy > 0)
    {
    o.style.height = (cy - Math.ceil(cy/5)) +"px";
    }
    else
    {
    clearInterval(proyc); 
    proxc = setInterval(function(){closex(o)},10);
    }
} 

function closex(o){/*--closeX--*/
    var cx = parseInt(o.style.width);
    if(cx > 0)
    {
	o.style.width = (cx - Math.ceil(cx/5)) +"px";
    }
    else
    {
    clearInterval(proxc);
    o.style.display = "none";
    }
} 


function CheckEmail(){ 
 var email = $('#email').val();
 var pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
 flag = pattern.test(email); 
 if(!flag){ 
  return false; 
 } 
 return (true); 
}

function checkAccount(){
var account = document.getElementById('cust_num').value
var account_format = /^[0-9]{10}$/
            return account_format.test(account)
}

function submit_email()
{			
		var o = document.getElementById('mail_msg');
		if ($('#full_name').val() == ""){
			o.style.display ='block';
			o.innerHTML = "Please enter the contact name.";
			}
		else if ($('#cust_num').val() == ""){
			o.style.display ='block';
			o.innerHTML = "Please enter a customer number.";
			}
		else if (!checkAccount()){
			o.style.display ='block';
			o.innerHTML = "Please enter a valid customer number.";
			}		
		else if ($('#subject').val() == ""){
			o.style.display ='block';
			o.innerHTML = "Please enter the subject.";
			}
		else if (!CheckEmail()){
			//$('#email').val() == ""
			o.style.display ='block';		
			o.innerHTML = "Please enter the valid email adress.";
			}			
		else if ($('#comments').val() == ""){
			o.style.display ='block';
			o.innerHTML = "Please enter your comments.";
			}
		else {
		//var comm = 	$('#comments').val();
		//comm = comm.replace(/\/n/g,'<br>');
		$.post("retailer_email.php",{
		full_name: $('#full_name').val(),
		store_name: $('#store_name').val(),
		cust_num: $('#cust_num').val(),
		subject: $('#subject').val(),
		email: $('#email').val(),
		telephone: $('#telephone').val(),
		comments: $('#comments').val()
		//comments: comm
		},function(txt){
		//alert(txt);
		if (txt == '1'){
			//o.innerHTML = "Your comments have been send to us successfully.";
			//$('#mail_msg').html() = "Your comments have been send to us successfully.";
			o.style.display ='block';
			o.innerHTML = "Thank you for your inquiry.<br>Please be assured that we will review your request <br>and respond as quickly as possible.";
			}
		else {
			o.innerHTML = "There is some problem that your comments can't been send to us.";		
			}
		
		
		});
		}
}

