/*
*************************************************************************
*	Sample of Open Window 												*
*************************************************************************
function openADViewWindow(ad_id, width, height){
	if(ad_id!=0){
		var args = 'width='+(String)(parseFloat(width)+20)+',height='+(String)(parseFloat(height)+20)+',status=0,address=0,resize=0';
		var popwindow = window.open('index.php?view=ad_view&ad_id='+ad_id,'ad_stat', args);
		if(!popwindow){
			alert("Your POP UP Blocker blocking a new window\n\nPlease disable any POP UP Blocker,\nor hold down CNTRL key while clicking on button/link");
		}
	}else{
		alert('Invalid operation !!');
	}
}
*************************************************************************


*************************************************************************
*	Sample of Ajax Usage												*
*************************************************************************
function toggle_user_status(user_id, stat){
	if(user_id!=0 && (stat==0 || stat==1)){
		new ajax ('ajax.php', {postBody: 'method=toggle_user_status&user_id='+user_id+'&stat='+stat, onComplete: toggle_user_status_callback});
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	}else{
		alert("Invalid operation. Please try later on !!");
	}
}

function toggle_user_status_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';//$("WAIT").hide();
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			alert("The users status has been changed successfully !!\n\nYou need to refresh this page to see the updated status");
			window.location.reload();
		}else{
			alert("We were not able to process your request\n\nPlease try later on");
		}
	}else{
		alert("We were not able to process your request\n\nPlease try later on");
	}
}
*************************************************************************
*/



function changeFieldValue(tablename,fieldname,fieldvalue,autoid,messagediv,messagetext){
	
	var userVarArray=new Array();
	userVarArray[0]=messagediv;
	userVarArray[1]=messagetext;
	
	new ajax ('ajax.php', {postBody: 'method=changefield&tablename='+tablename+'&fieldname='+fieldname+'&fieldvalue='+fieldvalue+'&autoid='+autoid, onComplete: changeFieldValue_callback,userVariable: userVarArray});
	
}

function changeFieldValue_callback(request,uservar){
	if(request!=null){
		
		
			
			
			if(request.responseText!=''){
				
				
						var messagediv=uservar[0];
						var messagetext=uservar[1];
						
						
						var success_icon="images/success_icon.gif";
						var messagestring="<table cellspacing=0 cellpadding=0 border=0><tr><td align='left' width='24' valign='top'><img src='"+success_icon+"'></td><td style='font-family: Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color:#006600; font-weight:normal'>"+messagetext+"</td></tr></table>";
						
						$(messagediv).innerHTML=messagestring;
							
					
			}
			
			
		
	}else{
		alert("We were not able to process your request\n\nPlease try later on");
	}
}

/*==================login popup==================================*/
function closeLoginPopupDiv(){
	$('loginPopupDIV').hide();
	$('COVER').hide();
}

function showLoginPopupDiv(val){
	
		if(val=="upload"){
			$('afterloginpage').value="postprojects";
		}
		if(val=="download"){
			$('afterloginpage').value="viewmyprojects";
		}
	
		
		$('loginPopupDIV').show();	
		
	
	
}
/*==================login popup==================================*/
/*====captcha verification=======*/
function validate_captcha(captcha_value, frm){
	//alert(frm);
	
	new ajax ('ajax.php', {postBody: 'method=validate_captcha&captcha_value='+captcha_value, onComplete: validate_captcha_callback, userVariable: frm});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function validate_captcha_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			uservar.submit();
		}else if(request.responseText=="INVALID"){
			alert("Invalid Verification Code !!");
			captchaNew();
		}else{
			captchaNew();
			alert("There was a problem communicating with the server\n\nPlease try later on");
		}
	}else{
		captchaNew();
		alert("There was a problem communicating with the server\n\nPlease try later on");
	}
}
/*====captcha verification=======*/



/*===========Function For Showing States according to Country=================*/
function showStates(country_id,stateDropDown){
	new ajax ('webadmin/ajax.php', {postBody: 'method=displaystates&country_id='+country_id, onComplete: showStates_callback,userVariable: stateDropDown});
}

function showStates_callback(request,uservar){
	if(request!=null){
		
			var stateDropDown=uservar;
							
			clearCombo(stateDropDown);
									
			if(request.responseText!=''){
			
				cntrl = document.getElementById(stateDropDown);
				var newOption, NameValuePair;
				var tmpArr = request.responseText.split("^");
												
				for(i=0;i<tmpArr.length;i++){
					NameValuePair = tmpArr[i].split("|");
					newOption = new Option();
					newOption.value = NameValuePair[0];
					newOption.text = NameValuePair[1];
					cntrl.options[cntrl.options.length]=newOption;
				}
						
			}
		
	}else{
		alert("We were not able to process your request\n\nPlease try later on");
	}
}

function clearCombo(ComboDropDown){
	
	var cntrl = document.getElementById(ComboDropDown);
	while(cntrl.options.length>0){
		cntrl.options[cntrl.options.length-1] = null;
	}
	var newOption = new Option();
	newOption.value = 0;
	newOption.text = "Select State";
	cntrl.options[cntrl.options.length]=newOption;
}
/*============================================================================*/