/*--------------------------------------------------------------------------*/
/*  functions.js is a JavaScript functions files to use Prototype framework */
/*  (c) 2006 Amir Iqbal <amirdoit@gmail.com>                                */
/*--------------------------------------------------------------------------*/

function submitpressRelease(){
	    var mailWindow =  window.open("pressrelease.asp","press","width=510,height=540,left=200,top=100,status=yes,resizable=No,scrollbars=yes");
	    mailWindow.focus();		
}

function hideDiv(divname){ 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(divname).style.visibility = 'hidden'; 
	}else{ 
		if (document.layers) { // Netscape 4 
		document.hideshow.visibility = 'hidden'; 
	}else{ // IE 4 
		document.all.hideshow.style.visibility = 'hidden'; 
	} 
} 
}
function showDiv(divname) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(divname).style.visibility = 'visible'; 
		document.getElementById(divname).style.position = 'absolute';
	}else { 
		if (document.layers) { // Netscape 4 
		document.hideshow.visibility = 'visible'; 
	} else { // IE 4 
		document.all.hideshow.style.visibility = 'visible'; 
	} 
}
}
var handlerFunc = function(t) {
alert(t);
    var msg = t.responseText
	 if(msg=="not"){
	    funError("Invalid...");
	}else{
		document.getElementById("loginWait").innerHTML='';
		hideDiv("loginWait");
		document.getElementById("manBox").innerHTML = msg;
		alert(msg);
	}
}

var errFunc = function(t) {
    alert('Error ' + t.status + ' -- ' + t.statusText);
}

function funWaiting(){
	var outputDiv2 = document.getElementById("loginWait");
	var mainDiv = document.getElementById("loginx");
		mainDiv.style.display = "none";
		outputDiv2.innerHTML = "<img border=0 src=images/login-wait.gif><br>Please wait..."		
		outputDiv2.style.display = "block";
		alert("ok");
		loginX();

}
function funSuccess(msg) {
	//hideDiv("loginWait");	
	//showDiv("welcome");
	showResponse1();
	//showResponseLogin(msg);	
}

function funError(msg) {
	alert(msg);
	var outputDiv2 = document.getElementById("loginErr");
	var mainDiv = document.getElementById("loginx");
	var outputDiv = document.getElementById("loginWait");
		outputDiv2.innerHTML = "<font color=#ff0000><b>"+msg+"</b></font>";
		outputDiv2.style.display = "block";
		mainDiv.style.display = "block";
		outputDiv.style.display = "none";
}

var logOut = function(t) {
    var msg = t.responseText
	 if(msg=="ok"){
		showDiv("loginx");	
		hideDiv("welcome");
		//hideDiv("loginWait");
	}
}


function loginX() {
	param = "user="+document.frmLogin.user.value+"&pass="+document.frmLogin.pass.value+"&func="+document.frmLogin.func.value;	
	new Ajax.Request('register.asp', {method: 'post', parameters: param , onSuccess:handlerFunc, onFailure:errFunc});
	alert(param);
}

function login() {
	param = "user="+document.frmLogin.user.value+"&pass="+document.frmLogin.pass.value+"&func="+document.frmLogin.func.value;	
	new Ajax.Request('register.asp', {method: 'post', parameters: param , onFailure:errFunc, onComplete: showResponseLogin});
}

function funLogout() {
	param = "func=logout"//+document.frmLogout.func.value;	
	new Ajax.Request('register.asp', {method: 'post', parameters: param , onFailure:errFunc, onComplete: showResponse1});
}

function gtPages(pgIx){
	param = "strPage="+escape(pgIx);			
	new Ajax.Request('pages.asp', {method: 'post', parameters: param , onFailure:errFunc, onComplete: showPages});		
}

function keywordSearch2(pgIx){
	if (document.frmSearch.q.value==""){
		alert('Please type a keyword to search.');
		document.frmSearch.q.focus();
		return false;
	}else if (document.frmSearch.q.value.length < 4) {
		alert('Your search text must be at least 4 characters long.\nTry again.');
		document.frmSearch.q.focus();
		return false;
	}else{	
		$('manbox').innerHTML='<br><br><img src=images/process.gif>&nbsp;<b>Loading...</b>'	
		param = "q="+escape($F('q'))+"&task="+escape($F('task'))+"&pageindex="+escape(pgIx);					
		new Ajax.Request('actionsearch.asp', {method: 'post', parameters: param , onFailure:errFunc, onComplete: showkeywordSearch});		
		return false;
	}
}

function cstmSearch(pgIx,chkf){
	if (($F('company')=="") && ($F('phone')=="") && ($F('pbox')=="")){
		alert('Please fill any of the fields.');
		document.frmCustom.company.focus();
		return false;
	}else{	
		if(chkf==1){
			$('manbox').innerHTML='<br><br><img src=images/process.gif>&nbsp;<b>Loading...</b>'	
			param = "company="+escape($F('company'))+"&phone="+escape($F('phone'))+"&pbox="+escape($F('pbox'))+"&task="+escape($F('task2'))+"&pageindex="+escape(pgIx);				
			new Ajax.Request('actionsearch.asp', {method: 'post', parameters: param , onFailure:errFunc, onComplete: showkeywordSearch});		
		}else{
			$('manbox').innerHTML='<br><br><img src=images/process.gif>&nbsp;<b>Loading...</b>'	
			param = "company="+escape($F('company'))+"&phone="+escape($F('phone'))+"&pbox="+escape($F('pbox'))+"&task="+escape($F('task2'))+"&pageindex="+escape(pgIx);				
			new Ajax.Request('actionsearch.asp', {method: 'post', parameters: param , onFailure:errFunc, onComplete: showkeywordSearch});		
			//alert(param)
			return false;
		}	
	}
}

function cstmClass(pgIx2,chkf2){
	if ($F('classified')=="0"){
		alert('Please select classification.');
		document.frmClassified.classified.focus();
		return false;
	}else{	
		if(chkf2==1){
			$('manbox').innerHTML='<br><br><img src=images/process.gif>&nbsp;<b>Loading...</b>'	
			param = "classified="+escape($F('classified'))+"&cmpdoc="+escape($F('cmpdoc'))+"&task="+escape($F('task2'))+"&pageindex="+escape(pgIx2);				
			new Ajax.Request('actionsearch.asp', {method: 'post', parameters: param , onFailure:errFunc, onComplete: showkeywordSearch});		
		}else{
			$('manbox').innerHTML='<br><br><img src=images/process.gif>&nbsp;<b>Loading...</b>'	
			param = "classified="+escape($F('classified'))+"&cmpdoc="+escape($F('cmpdoc'))+"&task="+escape($F('task2'))+"&pageindex="+escape(pgIx2);										
			new Ajax.Request('actionsearch.asp', {method: 'post', parameters: param , onFailure:errFunc, onComplete: showkeywordSearch});		
			//alert(param)
			return false;
		}	
	}
}

function alphaSearch(pgIx,stAplha){
	$('manbox').innerHTML='<br><br><img src=images/process.gif>&nbsp;<b>Loading...</b>'	
	param = "q="+escape(stAplha)+"&task=alphabet"+"&pageindex="+escape(pgIx);					
	new Ajax.Request('actionsearch.asp', {method: 'post', parameters: param , onFailure:errFunc, onComplete: showkeywordSearch});		
}



/*---Email the form---------------------------------------------------------------------------------------------*/
function chFrmMail(){

	var chk = true;
/*	if($F('subject').length<=2) {
		alert("Please enter the subject of your inquiry.");
		Field.focus('subject');
		return false;
		chk = false;
	}*/
	if($F('fname')=="") {
		alert("Please enter your first name.");
		Field.focus('fname');
		return false;
		chk = false;
	}
	if($F('lname')=="") {
		alert("Please enter your last name.");
		Field.focus('lname');
		return false;
		chk = false;
	}
	if($F('company')=="") {
		alert("Please enter your company name.");
		Field.focus('company');
		return false;
		chk = false;
	}
	if($F('email')=="") {
		alert("Please enter your email address.");
		Field.focus('email');
		return false;
		chk = false;
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($F('email'))){	
	} else	{
		alert("Invalid email address! Please re-enter.");
		Field.focus('email')
		return false;
		chk = false;
	}
	
	if($F('msg')=="") {
		alert("Please enter your comments.");
		Field.focus('msg');
		return false;
		chk = false;
	}

	if (chk=true) {
		//document.frmMail.style.display = 'none';
		//param = "subject="+escape($F('subject'))+"&"+"fname="+escape($F('fname'))+"&"+"email="+escape($F('email'))+"&"+"company="+escape($F('company'))+"&"+"address="+escape($F('address'))+"&"+"country="+escape($F('country'))+"&"+"city="+escape($F('city'))+"&"+"mobile="+escape($F('mobile'))+"&"+"tel="+escape($F('tel'))+"&"+"fax="+escape($F('fax'))+"&"+"msg="+escape($F('msg'))+"&"+"propose="+escape($F('propose'))+"&submit=yes";
		param = "fname="+escape($F('fname'))+"&"+"lname="+escape($F('lname'))+"&"+"company="+escape($F('company'))+"&"+"desgi="+escape($F('desgi'))+"&"+"email="+escape($F('email'))+"&"+"address="+escape($F('address'))+"&"+"city="+escape($F('city'))+"&"+"country="+escape($F('country'))+"&"+"phone="+escape($F('phone'))+"&"+"fax="+escape($F('fax'))+"&"+"mob="+escape($F('mob'))+"&"+"course="+escape($F('course'))+"&"+"msg="+escape($F('msg'))+"&submit=yes";
		$('msgBox').innerHTML='<br><br><img src=images/login-wait.gif>&nbsp;Please wait...'			
		//alert(param);
		var myAjax = new Ajax.Request( 'emailform.asp', {method: 'post', parameters: param, onComplete: showResponseMail} );
		
	}
}	
	
function showResponseMail(originalRequest) {
	$('msgBox').innerHTML = originalRequest.responseText;
}
/*End Email Form--------------------------------------------------------------------------------------------------------*/
function showResponse1(originalRequest){
	$('loginx').innerHTML = originalRequest.responseText;
}
function showkeywordSearch(originalRequest){
	$('manbox').innerHTML = originalRequest.responseText;
}
function showPages(originalRequest){
	$('manbox').innerHTML = originalRequest.responseText;
}
function showResponseLogin(originalRequest) {
	hideDiv("loginWait");
	$('loginx').innerHTML = originalRequest.responseText;
}


//////////////////////////////////////////////////////NewsLetter Script///////////////////////////////////////////////////////
function FormAddSubscriber_Validator(theForm){
	// check if email field is blank
	var form_email = theForm.txtEmail.value;
	var invalidChars = " /:;,"
	var badChar =""
	if (form_email== ""){
		alert("You must enter an email");
		theForm.txtEmail.focus();
		return (false);
	}
	for (i = 0;  i < invalidChars.length;  i++){
		badChar=invalidChars.charAt(i);
		if(form_email.indexOf(badChar,0)>-1){
		alert("You cannot have a /:;, or a space");
		theForm.txtEmail.focus();
		return (false);
		}
	}
	atPos=form_email.indexOf("@",1)
	if(atPos==-1){
		alert("Your Email is not Valid, must have an @");
		theForm.txtEmail.focus();
		return (false);
	}
	if(form_email.indexOf("@",atPos+1)>-1){
		alert("You cannot have two @'s");
		theForm.txtEmail.focus();
		return (false);
	}
	periodPos=form_email.indexOf(".",atPos)
	if(periodPos==-1){
		alert("There must be an . in your email address");
		theForm.txtEmail.focus();
		return (false);
	}
	if(periodPos+3>form_email.length){
		alert("There must be atleast two letters after .");
		theForm.txtEmail.focus();
		return (false);
	}
	return(true);
}


function FormSendEmail_Validator(theForm){

if(theForm.txtFrom.value==""){
alert("You must enter who the email is from");
theForm.txtFrom.focus();
return (false);
}

if(theForm.txtSubject.value=="")
{
alert("You must enter a subject");
theForm.txtSubject.focus();
return (false);
}

if(theForm.txtBody.value=="")
{
alert("You must enter your email body.");
theForm.txtBody.focus();
return (false);
}

return(true);
}


function FormSubscribe(theForm)
{
// check if email field is blank
var form_email = theForm.txtEmail.value;
var invalidChars = " /:;,"
var badChar =""
if (form_email== "")
{
alert("You must enter an email");
theForm.txtEmail.focus();
 return (false);
}
for (i = 0;  i < invalidChars.length;  i++)
{
badChar=invalidChars.charAt(i);
if(form_email.indexOf(badChar,0)>-1)
{
alert("You cannot have a /:;, or a space");
theForm.txtEmail.focus();
return (false);
}
}
atPos=form_email.indexOf("@",1)
if(atPos==-1)
{
alert("Your Email is not Valid, must have an @");
theForm.txtEmail.focus();
return (false);
}
if(form_email.indexOf("@",atPos+1)>-1)
{
alert("You cannot have two @'s");
theForm.txtEmail.focus();
return (false);
}
periodPos=form_email.indexOf(".",atPos)
if(periodPos==-1)
{
alert("There must be an . in your email address");
theForm.txtEmail.focus();
return (false);
}
if(periodPos+3>form_email.length)
{
alert("There must be atleast two letters after .");
theForm.txtEmail.focus();
return (false);
}
return(true);
}

function openPoP(myForm){
	var w = window.open('about:blank','newsletter','height=150 width=300');
	myForm.target = 'newsletter';
	return true;
}
//////////////////////////////////////////////////////End NewsLetter Script///////////////////////////////////////////////////////

