var gSrc = ''
function get_val(){
  if (http.readyState==4) {
    var filecont = parseInt(http.responseText);
	
	if (gSrc=="frame1") {
	var Keyword = parent.document.getElementById('Keyword').value;
	var totalSearches = parseInt(parent.document.getElementById('totalSearches').value);
	var remainingSearch = totalSearches - filecont;
	if (!isNaN(remainingSearch)) {
	parent.document.getElementById('remainingSearchesDiv').innerHTML = remainingSearch;
	} 
	if (remainingSearch<=0) {
	   parent.document.getElementById('searchArea').innerHTML = '<div align="center" style="color:#c10000">Please Buy new Searches, Your search limit is over. <input type="hidden" id="Keyword" value="'+ Keyword +'"></div>';	
	}
	} else {
		var Keyword = parent.parent.document.getElementById('Keyword').value;
	var totalSearches = parseInt(parent.parent.document.getElementById('totalSearches').value);
	var remainingSearch = totalSearches - filecont;
	if (!isNaN(remainingSearch)) {
	parent.parent.document.getElementById('remainingSearchesDiv').innerHTML = remainingSearch;
	} 
	if (remainingSearch<=0) {
	   parent.parent.document.getElementById('searchArea').innerHTML = '<div align="center" style="color:#c10000">Please Buy new Searches, Your search limit is over. <input type="hidden" id="Keyword" value="'+ Keyword +'"></div>';	
		
	 }
	}
  }
}




function help_page()
{
	var iframeElement = parent.parent.document.getElementById('FF'); 
	  iframeElement.style.height = 525; //100px or 100% 
	  
	var arr = new Array("dashboard","supply","demand","analysis","competition");
	for (i=0; i<arr.length; i++) 
	{
	  document.getElementById(arr[i]).style.background = "url(../images/marketwizard/tabs/tab_blue.jpg) left top no-repeat";
	  document.getElementById(arr[i] + "_li").style.top = "0px";
	  document.getElementById(arr[i]).style.color= "#FFFFFF";
	  
	}
		 frames['myframe'].location.href = "preview/help.php";
}

function getSearch(param,src) {
   gSrc = src;
   http.open("GET", "../get_count.php?param=" + param,false);
   http.onreadystatechange = get_val ;
   http.send(null);
}


/*function get_tabinfo(){
  if (http.readyState==4) {
    var filecont = http.responseText;
	
	parent.parent.document.getElementById('INFOBOX_INFO').innerHTML =  "<br>"+filecont+"<br><br>";
  } else {
    parent.parent.document.getElementById('INFOBOX_INFO').innerHTML = '<div align="center"><img src="Images/loading.gif" border="0"></div>';	  
  }
}




function getInfobox(param) {
	
  if(window.location.href.length>90)  // when dashbard link is clicked,its location will b more than 100 otherwise less then 100
		http.open("GET", "../get_info.php?param=" + param,false);
	else
	   http.open("GET","get_info.php?param=" + param,true);
   http.onreadystatechange = get_tabinfo ;
   http.send(null);
}

*/


function create_http_object(){
  var httpxml=false;
  /*@cc_on 
    @if (@_jscript_version>=5) 
	  try {
	    httpxml = new ActiveXObject("Msxml12.XMLHTTP");
	  } catch(e) {
	    try {
		  httpxml = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e2) {
		  httpxml = false;
		}
	  }
   @end @*/ 
   if (!httpxml && typeof XMLHttpRequest != 'undefined') {
    httpxml = new XMLHttpRequest();
   }
return httpxml;
}
http = create_http_object();
function Validate_pass() {
		var frm = document.getElementById('frmNewUser');
		var oldpass = Trim(frm.oldpass.value);
		var newpass = Trim(frm.newpass.value);
		var repass = Trim(frm.repass.value);
		var error_str = '';
		
		if (oldpass.length < 1)
		{
			error_str+="Error : Old Password is required<br>";
		}
		if (newpass.length < 1)
		{
			error_str+="Error : New Password is required<br>";
		}
		if (repass.length < 1)
		{
			error_str+="Error : Re-enter New Password<br>";
		}
		if (newpass != repass)
		{
			error_str+="Error : New Password and Re-entered Password doesnot match<br>";
		}
		if (error_str) {
			 document.getElementById("ERR_DISP").style.display = "block";
			 document.getElementById("Error_Label").innerHTML = error_str;
			 return false;
		} 
	return true;
}
 function show_login_form_errors() {
	
	var ErrorStr;
	trimForm();
	ErrorStr="";
	if (document.LoginFrm.LoginId.value=="") {
		 ErrorStr +="Error : Please Enter Username<br>";
		  
		}
	if (document.LoginFrm.Pwd.value=="") {
		 ErrorStr +="Error : Please Enter Password<br>";
		  
		}	
	if (ErrorStr!="") {
		ErrorStr += "<br>";	
		document.getElementById("ErrorLable").innerHTML= ErrorStr;
		} else LoginFrm.submit();
	
}
function MyTrim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function trimForm()
{
	for(field in document.getElementsByTagName("input"))
	{
		try{
		document.getElementById(field).value=MyTrim(document.getElementById(field).value);
		}catch(e)
		{}
	}
	for(field in document.getElementsByTagName("textarea"))
	{
		try{
		document.getElementById(field).value=MyTrim(document.getElementById(field).value);
		}catch(e)
		{}
	}
}

function Validate_upass() {
		var frm = document.getElementById('frmNewUser');
		
		var newpass = Trim(frm.newpass.value);
		var repass = Trim(frm.repass.value);
		var error_str = '';
		
		if (newpass.length < 1)
		{
			error_str+="Error : New Password is required<br>";
		}
		if (repass.length < 1)
		{
			error_str+="Error : Re-enter New Password<br>";
		}
		if (newpass != repass)
		{
			error_str+="Error : New Password and Re-entered Password doesnot match<br>";
		}
		if (error_str) {
			 document.getElementById("ERR_DISP").style.display = "block";
			 document.getElementById("Error_Label").innerHTML = error_str;
			 return false;
		} 
	return true;
}
function popup(src,wid,hei){
	    
	    winleft = screen.width/2 - wid/2;
		wintop = screen.height/2 - hei/2;
	    window.open(src,"","toolbar=no,scrollbars=no,resizable, status=yes,width="+wid+",height="+hei+",top="+wintop+",left="+winleft);
	}
function popupScroll(src,wid,hei){
	    winleft = screen.width/2 - wid/2;
		wintop = screen.height/2 - hei/2;
	    window.open(src,"","toolbar=no,scrollbars=yes,resizable, status=yes,width="+wid+",height="+hei+",top="+wintop+",left="+winleft);
	}
	
function Validate()
	{
		var frm = document.getElementById('frmNewUser');
		var usrName = Trim(frm.uname.value);
		var passwrd = Trim(frm.pwd.value);
		var repasswrd = Trim(frm.repwd.value);
		var emailad = Trim(frm.email.value);
		var adcat = Trim(frm.ad_cat.value);
		var error_str = '';
		
		
		if (usrName.length < 1)
		{
			error_str+="Error : User Name is required<br>";
		}
		if (passwrd.length < 1)
		{
			error_str+="Error : Password is required<br>";
		}
		if (passwrd != repasswrd)
		{
			error_str+="Error : Password and Confirm Password doesnot match<br>";
		}
		if (adcat == -1)
		{
			error_str+="Error : Please Choose a Permission Level for this User<br>";
		}
		if (emailad.length<1)
		{
			error_str+="Error : Email Address is required<br>";
		} else if (!isEmail(emailad)) {
			  error_str+="Error : Invalid Email Address<br>";
			} 
		if (error_str) {
			 document.getElementById("ERR_DISP").style.display = "block";
			 document.getElementById("Error_Label").innerHTML = error_str;
			 return false;
		}
		
		return true;
	}
function isEmail(string) {
if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
else
return false;
}

function Message()
	{
		alert("Not implemented yet");
	}
function checkEmail(emailCntrl)
{
	if(emailCntrl.value=="")
	{
		return "Please enter e-mail address.";
	}
	else
	{
		mail=emailCntrl.value
		at_pos=mail.indexOf("@")
		dot_pos=mail.indexOf(".")
		if(at_pos<1 || dot_pos<1)
		{
			return "Please enter valid email address.";
		}
		else
		{
			mail=emailCntrl.value
			condition="yes"
			var at_count=0
			var dot_count=0
			var temp=0
			for(var i=0;i<mail.length;i++)
			{
				if((mail.charCodeAt(i)>0 && mail.charCodeAt(i)<48)||(mail.charCodeAt(i)>57 && mail.charCodeAt(i)<65)||(mail.charCodeAt(i)>91 && mail.charCodeAt(i)<97)||mail.charCodeAt(i)>122)
				{
					if(mail.charAt(i)=="@"||mail.charAt(i)==".")
					{
							if(mail.charAt(i)=="@"){at_count++}else{dot_count++} // counts the no. of times @ and . appears in email
							if(dot_count>=1)
							{
								dot_pos=i
								if((dot_pos>at_pos) && temp==0)
								{
									pos=dot_pos-at_pos
									temp++
								}								
							}
					}
					else
					{
						condition="no"
						i=mail.length
					}
				}
			}
			if(condition=="no")
			{
				alert("Your email contains a blank space or special character.")
				emailCntrl.focus()
				ok=false
			}
			else
			{
				if(at_count>1)
				{
					alert("E-mail contains extra @ ")
					emailCntrl.focus()
					ok=false
				}
				else
				{
					if(pos<2)
					{
						alert("Missing domain name between '@' and '.'")
						emailCntrl.focus()
						ok=false
						i=mail.length
					}
					else
					{	
						count=dot_pos+1
						domain=""
						for(count;count<mail.length;count++)
						{
							domain=domain+mail.charAt(count)		
						}
						dom=new Array("au","com","net","org","edu","in","mil","gov","arpa","biz","aero","name","coop","info","pro","museum")
						error="yes"
						for(var k=0;k<dom.length;k++)
						{
							if(domain==dom[k])
							{
								k=dom.length
								error="no"
							}
						}
						if((error=="yes" && (domain.length>2)) || (domain.length<2))
						{
							alert("Domain name must end with well known domains \n or 2-lettered country name. eg com,edu,in etc.")
							emailCntrl.focus()
							ok=false
						}								
					}
				}
			}
		}
	}
	return ok
}

function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}

function isName(value)
{
	for(i=0;i<value.length;i++)
	{			
		ch = value.charAt(i);
		if ( ((ch <= "z") && (ch >= "a")) || ((ch <= "Z") && (ch >= "A")) || (ch == ' ') || (ch == " ") ) {}
		else 
 			return false;
	}
 	return true;
}
function isDigit(value)
{
	var digit = Boolean(true);
    	for(var i=0;i<value.length;i++)
    	{
      	  var ch = value.charAt(i);
      	  if(!(ch == "0" || ch=="1" || ch=="2" || ch=="3" || ch=="4" || ch=="5" || ch=="6" || ch=="7" || ch=="8" || ch=="9"))
   	  	return false;
      	}
	return true;
}
function isFloat(field)
{
	var point=0;
	var i=0;
	var beforePoint=0;
	var afterPoint=0;
	for(var a=0;a<field.length;a++)
	{
    	if(!(field.charAt(a)=="." || field.charAt(a)=="0" || field.charAt(a)=="1" || field.charAt(a)=="2" || field.charAt(a)=="3" || field.charAt(a)=="4" || field.charAt(a)=="5" || field.charAt(a)=="6" || field.charAt(a)=="7" || field.charAt(a)=="8" || field.charAt(a)=="9"))
			return false;
		if(field.charAt(a)==".")
			point++;
	}
	if(point > 1)
		return false;
	if(point == 1)
	{
		while(field.charAt(i)!=".")
		{
			i++;
			beforePoint++;
		}
		afterPoint=field.length-(beforePoint+1);
		if(beforePoint > 3)
			return false;
		if(afterPoint > 4)
			return false;
		if(afterPoint==0 && beforePoint==0)
			return false;
	}
	return true;
}	
function show_hide (obj){
   if (document.getElementById(obj).style.display == "none"){
     document.getElementById(obj).style.display = "block";
   } else {
     document.getElementById(obj).style.display = "none" ;
   }
  
}


// MEMEBERS ONLY POP-UP
function newWindow (mypage,myname,w,h,features)

  {

  	if(screen.width)

  	{

  		var winl = (screen.width-w)/2;
  		var wint = (screen.height-h)/2;

  	}

  	else

  	{

  		winl = 0;wint =0;

  	}

  	if (winl < 0) winl = 0;
  	if (wint < 0) wint = 0;

  	var settings = 'height=' + h + ',';
  	settings += 'width=' + w + ',';
  	settings += 'top=' + wint + ',';
  	settings += 'left=' + winl + ',';
  	settings += features;
  	settings += ' scrollbars=yes ';

  	win = window.open(mypage,myname,settings);

  	win.window.focus();

  }