var xmlHttpCon;
var xmlHttpReq;
var setRefT;

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}


	// For IE4+
	ie=(document.all)?true:false;
	// For Mozilla
	dom=((document.getElementById) && (!ie))?true:false;
	
	if (dom){
		objclsName='class';
	} else if (ie){
		objclsName='className';	
	}
	
	function objSetStyleAttribs(obj, params){
		if (dom){
			obj.setAttribute("style", params);
		} else if (ie){
			myStyle = obj.style;
			myStyle.cssText = params;
			obj.setAttribute("style", myStyle);
		}
	}
	
	
	
	function getElementIDFix(layerId)
	{
		var elem;
		if( document.getElementById ){ // this is the way the standards work
			elem = document.getElementById(layerId);
		}else if( document.all ){ // this is the way old msie versions work
			elem = document.all[layerId];
		}else if( document.layers ){ // this is the way nn4 works
			elem = document.layers[layerId];
		}
		return elem;
	}

	var oldonload = window.onload;
	if (window.addEventListener) {//DOM method for binding an event
	window.addEventListener("load", initOnloadEvents, false);
	} else if (window.attachEvent) {//IE exclusive method for binding an event
	window.attachEvent("onload", initOnloadEvents);
	} else if (document.getElementById) {//support older modern browsers
		window.onload = function(){
		oldonload();
		initOnloadEvents();
		}
	}
	
	 function initOnloadEvents(){
	 }



function getKey(e){
	var kC  = (window.event) ? event.keyCode : e.keyCode; // MSIE or Firefox?
	var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE; // MSIE : Firefox?
	if(kC == Esc){ swapLoginBox(); }	
}

function listenKey () {	
	document.onkeypress = getKey; 
}


function swapLoginBox(){
	var myab=getElementIDFix('login_box');
	if (myab.style.display == 'block'){
		hideBox('login_box');
		hideBox('login_box_overlay');
		// disable keypress listener
		document.onkeypress = '';
		
	} else {
		showBox('login_box_overlay');
		showLoginBox('login_box','my_loginimg');
		listenKey ();
	}
}

function showLoginBox(layerId,str_linkimg)
{
	var elem=getElementIDFix(layerId);
	var imgelem=getElementIDFix(str_linkimg);
	var posArr=findPos(imgelem);
	elem.style.display = 'block';
	elem.style.top= posArr[1]+imgelem.offsetHeight+2+'px';
	elem.style.left= (posArr[0]-((elem.offsetWidth-imgelem.offsetWidth)/2))+"px";
}

function showBox(layerId)
{
	var elem=getElementIDFix(layerId);
	elem.style.display = 'block';
}

function hideBox(layerId)
{
	var elem=getElementIDFix(layerId);
	elem.style.display = 'none';
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	return [curleft,curtop];
	}
}
	 
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 getVid(vidID)
{
getElementIDFix("flash_player").innerHTML='<object height="202" width="286" data="http://www.youtube.com/watch/v/'+vidID+'" type="application/x-shockwave-flash"><param value="http://www.youtube.com/watch/v/'+vidID+'" name="movie"/><param value="high" name="quality"/><param value="transparent" name="wmode"/></object>';
} 


function validateRequestForm(obj){

	if (obj.reqName.value==""){
		alert("Name Required!"); 
		obj.reqName.focus(); 
		return false;
	}
					 
	if (obj.reqSong.value==""){
		alert("Request (Song/Artist) Required!"); 
		obj.reqSong.focus(); 
		return false;
	}
					 					 
	if (obj.reqEmail.value==""){
		alert("Email Required!"); 
		obj.reqEmail.focus(); 
		return false;
	}
	
	if (obj.reqEmail.value.trim()==""){
		alert("Email Required!"); 
		obj.email.focus(); 
		return false;
	} else {
		var email=obj.reqEmail.value;
		var myRegxp=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (!(myRegxp.test(email))){
			alert("Invalid Email address"); 
			obj.reqEmail.focus(); 
			return false;
		}
	}
	
return true;
}

function RequestSubmit(formobj)
{
	xmlHttpReq=GetXmlHttpObject();
	if (xmlHttpReq==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	
	params= '&reqName='+encodeURIComponent(formobj.reqName.value)+
			'&reqSong='+encodeURIComponent(formobj.reqSong.value)+
			'&reqDedicate='+encodeURIComponent(formobj.reqDedicate.value)+
			'&reqEmail='+encodeURIComponent(formobj.reqEmail.value);

	hideBox('requestform');
	showBox('requestmsg');
	
	xmlHttpReq.open("POST", 'request.php?op=submitRequest', true);
	xmlHttpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpReq.setRequestHeader("Content-length", params.length);
	xmlHttpReq.setRequestHeader("Cache-Control", "no-cache"); 
	xmlHttpReq.setRequestHeader("Connection", "close");
	xmlHttpReq.onreadystatechange=requestStateChanged;
	xmlHttpReq.send(params);
} 

function requestStateChanged() 
{ 
	var loadstat='<center><img src="theme/images/loading.gif" alt="Loading..." title="Loading..."><br/><b>Loading.....</b></center>';
	if (xmlHttpReq.readyState==4 && xmlHttpReq.status == 200){ 
		document.getElementById("requestmsg").innerHTML=xmlHttpReq.responseText;
		evalAjaxContent(xmlHttpReq.responseText);
	} else if (xmlHttpReq.readyState==1 || xmlHttpReq.readyState==2 || xmlHttpReq.readyState==3){ 
		document.getElementById("requestmsg").innerHTML=loadstat;
	}
}


String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
};

function validateContactUSForm(){
	if (document.getElementById("con_name").value.trim()==""){
		alert("Contact Name Required!"); 
		document.getElementById("con_name").focus(); 
		return false;
	} 

	if (document.getElementById("con_phone").value.trim()!=""){
		strp=CharsInList(document.getElementById("con_phone").value,"()- +");
		if(!(isNumInteger(strp) && strp.length >= 10)){
			alert("Invalid Phone Number.");
			document.getElementById("con_phone").focus(); 
			return false;
		}
	} else {
		alert("Required Phone Number.");
		document.getElementById("con_phone").focus(); 
		return false;
	}


	var email=document.getElementById("con_email").value.trim();
	var myRegxp=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (!(myRegxp.test(email))){
		alert("Invalid Email address"); 
		document.getElementById("con_email").focus(); 
		return false;
	}


	if (document.getElementById("con_inqtype").options[document.getElementById("con_inqtype").selectedIndex].value.trim()==""){
		alert("Invalid Inquiry Selection"); 
		document.getElementById("con_inqtype").focus(); 
		return false;
	}

	if (document.getElementById("con_inquiry").value.trim()==""){
	alert("Invalid Inquiry"); 
	document.getElementById("con_inquiry").focus(); 
	return false;
	}


return true;
}



function ContactUSSubmit(formobj)
{
	xmlHttpCon=GetXmlHttpObject();
	if (xmlHttpCon==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 


	params= '&con_name='+encodeURIComponent(formobj.con_name.value)
		+'&con_title='+encodeURIComponent(formobj.con_title.value)
		+'&con_company='+encodeURIComponent(formobj.con_company.value)
		+'&con_phone='+encodeURIComponent(formobj.con_phone.value)
		+'&con_email='+encodeURIComponent(formobj.con_email.value)
		+'&con_inqtype='+encodeURIComponent(formobj.con_inqtype.options[formobj.con_inqtype.selectedIndex].value)
		+'&con_inquiry='+encodeURIComponent(formobj.con_inquiry.value);

//	hideBox('MainContent');
	showBox('SubContent');
	
	xmlHttpCon.open("POST", 'contactus.php'+params, true);
	xmlHttpCon.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpCon.setRequestHeader("Content-length", params.length);
	xmlHttpCon.setRequestHeader("Cache-Control", "no-cache"); 
	xmlHttpCon.setRequestHeader("Connection", "close");
	xmlHttpCon.onreadystatechange=subContentChanged;
	xmlHttpCon.send(params);
} 


function isNumInteger(n)
{   var i;
    for (i = 0; i < n.length; i++)
	   {   
 	        var chr = n.charAt(i);
	        if (((chr < "0") || (chr > "9"))) return false;
	   }
	    return true;
}

function CharsInList(str, list)
{   var i;
    var returnStr = "";
    for (i = 0; i < str.length; i++)
    {   
        var chr = str.charAt(i);
        if (list.indexOf(chr) == -1) returnStr += chr;
    }
    return returnStr;
}

function subContentChanged() 
{ 
	var loadstat='<center><img src="theme/images/loading.gif" alt="Loading..." title="Loading..."><br/><b>Loading.....</b></center>';
	if (xmlHttpCon.readyState==4 && xmlHttpCon.status == 200){ 
		document.getElementById("SubContent").innerHTML=xmlHttpCon.responseText;
		evalAjaxContent(xmlHttpCon.responseText);
	} else if (xmlHttpCon.readyState==1 || xmlHttpCon.readyState==2 || xmlHttpCon.readyState==3){ 
		document.getElementById("SubContent").innerHTML=loadstat;
	}
}


function evalAjaxContent(content) { 
  while(true) {
    var sindex = content.indexOf('<script type="text/javascript">');
    if(sindex < 0) { break; }
	content = content.substring(sindex);
    var eindex = content.indexOf("</script>");
	eval(content.substring(content.indexOf('>')+1,eindex));
    content = content.substring(eindex+9, content.length);
  }
}




function resetRequestForm(){
obj=getElementIDFix('frmRequest');
obj.reqName.value="";
obj.reqSong.value="";
obj.reqDedicate.value="";
obj.reqEmail.value="";

obj.reqName.focus(); 
}


function playClip(clip){
	var s1 = new SWFObject("theme/flash/flvplayer.swf","mply","280","76","9","#FFFFFF");
	s1.addParam("allowfullscreen","false");
	s1.addParam("allowscriptaccess","always");
	s1.addParam("wmode","opaque"); 
	s1.addVariable("file", clip);
	s1.addVariable("image", "theme/images/programs/player/mihila_player_bg.jpg");
	s1.addVariable("autostart","true");
	s1.write("flv_ap");
}
