// JavaScript Document



function clearText(ob){
if(ob.value =='email / user id' || ob.value=='password'){
	ob.value='';
}

}

function setFirstText(ob){

if(ob.value ==''){

ob.value='email / user id';
}
}

function setLastText(ob){

if(ob.value ==''){

ob.value='password';
}
}


function checkRef(){
	
	var reference = document.getElementById("reference").value;
	//alert("reference " + " : " + reference);
	//var proname = proname.id;
		if(reference=="other"){
		document.getElementById("ref_other").style.display = '';
	}else{
		//document.getElementById("p1_pmc").disabled=true;
		 document.getElementById("ref_other").style.display = 'none';
		
	}
		
	
}


	
/*
Function to validate ADvertiser form
*/		
function valForm_advertiser(theform)
{
	var fname = document.getElementById("fname").value;
	var lname = document.getElementById("lname").value;
	var emailid = document.getElementById("emailid").value;
	var phone = document.getElementById("phone").value;
	var company = document.getElementById("company").value;
	var website = document.getElementById("website").value;
	var message = document.getElementById("message").value;
//	var reference= document.getElementById("reference").value;
	var country= document.getElementById("country").value;
	
	//alert(fname);
	if(fname==""){
		showError("The first name cannot be left blank");
		document.getElementById("fname").focus();
		changeError('fname')
		return false;
	}else if(isNum(fname)){
			//alert("name " + name);
			showError("Numbers are not allowed in the first name");
			document.getElementById("fname").focus();
			changeError('fname')
			return false;
	}
	else if(isSpchar(fname)){
			showError("Special characters not allowed in the first name");
			document.getElementById("fname").focus();
			changeError('fname')
			return false;
	}
	else{
		changeProper('fname')
	}
	
	if(lname==""){
		showError("The last name cannot be left blank");
		document.getElementById("lname").focus();
		changeError('lname')
		return false;
	}else if(isNum(lname)){
			//alert("name " + name);
			showError("Numbers are not allowed in the last name");
			document.getElementById("lname").focus();
			changeError('lname')
			return false;
	}
	else if(isSpchar(lname)){
			showError("Special characters not allowed in the last name");
			document.getElementById("lname").focus();
			changeError('lname')
			return false;
	}
	else{
		changeProper('fname')
	}
	
	if(emailid==""){
		showError("The Email Id cannot be left blank");
		document.getElementById("emailid").focus();
		changeError('emailid');
		return false;
	}else{
		changeProper('emailid')
	} 
	
	if(!isValidEmail(emailid))
	{
		showError("Invalid email address.");
		document.getElementById("emailid").focus();
		changeError('emailid')
		return false;
	}else{
		changeProper('emailid')
	}
	
	if(phone==""){
		showError("Phone Number should not be blank");
		document.getElementById("phone").focus();
		changeError('phone')
		return false;
	}else{
		changeProper('phone')
	}
	
	if(!isNumber(phone))
	{
		showError("Please enter numbers only");
		document.getElementById("phone").focus();
		changeError('phone')
		return false;
	}else{
		changeProper('phone')
	}
	
	if(company==""){
		showError("The Company cannot be blank");
		document.getElementById("company").focus();
		changeError('company')
		return false;
	}else{
		changeProper('company')
	}
	
	if(website==""){
		showError("The Website cannot be blank");
		document.getElementById("website").focus();
		changeError('website')
		return false;
	}else{
		changeProper('website')
	}
	
	
	/*
	if(message==""){
		showError("The Message cannot be blank");
		document.getElementById("message").focus();
		changeError('message')
		return false;
	}else{
		changeProper('message')
	}
	*/
	
	if(country==""){
		showError("Please select your country");
		document.getElementById("country").focus();
		changeError('country')
		return false;
	}else{
		changeProper('country')
	}
	
		toogleElement('msg','none')
		//showThanks(theform)
		
		
}		

/*
Common Function to validate contact form
*/	
function trim(str)
{ 
	return((""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}

function isSpchar(value){
  var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?";

  for (var i = 0; i < value.length; i++) {
  	if (iChars.indexOf(value.charAt(i)) != -1) 
  	{
  		return true;
  	}
  }	
  return false;
}

function isNumber(str){
	
//	var filter=/^[\d]+$/;
	var filter=/^[0-9]+$/;
	if(filter.test(trim(str)))
	return true;
	else
	return false;
}

function isNum(value){
  var iChars = "0123456789";

  for (var i = 0; i < value.length; i++) {
  	if (iChars.indexOf(value.charAt(i)) != -1) 
  	{
  		return true;
  	}
  }	
  return false;
}

function isValidEmail(value){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(filter.test(trim(value)))
		return true;
	else
		return false;
	
}

function toogleElement(EleName,style){
	var objEle = document.getElementById(EleName);
	if(objEle)
		objEle.style.display=style;
}

function showNotification(msg){
	showStatus(msg,'statusMsg');
}
function showError(msg){
	showStatus(msg,'statusErr');
}
function showStatus(msg,type){

	var ele = document.getElementById('msg');
	ele.innerHTML = msg;
	ele.className = type;

	toogleElement('msg','block');
	try{
	increaseHeight()
	}catch(e){}
}

function changeError(id){
	document.getElementById(id).style.borderStyle="solid";
	document.getElementById(id).style.borderColor="red";
	}
function changeProper(id){
	document.getElementById(id).style.borderStyle="";
	document.getElementById(id).style.borderColor="";
	}

function showThanks(formdiv){
	toogleElement(formdiv,'none');
	toogleElement('thanks','block');
}
function showform(url){
	location=url;
}



/*
Alternate row color
*/


//window.onload=function()
/*
{	var b, r, t = document.getElementsByTagName("TABLE");

	for(var i=0; i<t.length; i++)
	{	
		var current_t = t[i];
		if(current_t)
		{	
			b = current_t.getElementsByTagName("TBODY");
			
			for(var j=0; j<b.length; j++)
			{	
				var current_b = b[j];
				r = current_b.getElementsByTagName("TR");
				//alert(r.length);
				for(var k=0; k<r.length; k++)
				{	
					if(k % 2 == 0){ 
					   r[k].className = "white";
					 }else{ 
					   r[k].className = "grey";
					 }       
					//r[k].className = "udda";
				}
			}
		}
	}
}
*/
function alternateRows()
{	
	
	var b, r, t = document.getElementsByTagName("TABLE");
//	alert("parvez");	
	for(var i=0; i<t.length; i++)
	{	
		var current_t = t[i];
		if(current_t)
		{	
			r = current_t.getElementsByTagName("TR");
			
			for(var j=0; j<r.length; j++)
			{	
				
					if(j % 2 == 0){ 
					   r[j].className = "white";
					 }else{ 
					   r[j].className = "grey";
					 }       
					
				
			}
		}
	}
}


/*
function alternatecolor(id){ 
 if(document.getElementsByTagName){  
   var table = document.getElementById(id);  
   var rows = table.getElementsByTagName("tr");  
   for(i = 0; i < rows.length; i++){           
     if(i % 2 == 0){ 
       rows[i].className = "color_one";
     }else{ 
       rows[i].className = "color_two";
     }      
   }
 }
}
*/




function medopen() {
coolopenWindow=window.open("/flash/mediakit.html","medopen","scrollbars=0,menubar=0,statusbar=0,toolbar=0,height=560,width=362,outerheight=562,outerwidth=364"); 	
coolopenWindow.focus(); }

function updateopen() {
coolopenWindow=window.open("/publishers/update_schedule.html","updateopen","scrollbars=0,menubar=0,statusbar=0,toolbar=0,height=300,width=362,outerheight=562,outerwidth=364"); 	
coolopenWindow.focus(); }

function expireopen(program_id) {
window.open("/publishers/help/program_expire_popup.html?program_id=" + program_id,"open","scrollbars=0,menubar=0,statusbar=0,toolbar=0,height=150,width=362,outerheight=150,outerwidth=364"); 	
}
function openWin(url) 
{
	aWindow = window.open(url,"thewindow",'toolbar=0,location=0,directories=0,status=0,menubar=0, width=400, height=400, scrollbars, resizable');	
	aWindow.focus();
}



