var post_vars = "";
var form_name = "";
var id_list = "";
var xmlhttp_s = new_http_object();//(window.XMLHttpRequest ? new XMLHttpRequest(): ((window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : null) );
var target_msg_id_draft = "";
function new_http_object(){
	var xmlobj = null;
	// try to instantiate the native XMLHttpRequest object
	try{// create an XMLHttpRequest object
		xmlobj = new XMLHttpRequest();
	}
	catch(e){// assume IE6 or older
		try{
			xmlobj = new ActiveXObject("Microsoft.XMLHttp");
		}
		catch(e){ }
	}
	// return the created object or display an error message
//	if (!xmlHttp)
//		alert("Error creating the XMLHttpRequest object.");
//	else
	return xmlobj;
}

function get_form_value(){
    
    generated_string = "";
    for (i=0; document.forms[form_name][i]; i++){
        if(document.forms[form_name][i].type == 'checkbox'){
		generated_string += "&" + document.forms[form_name][i].id + "=" + (document.forms[form_name][i].checked?document.forms[form_name][i].value:'');
		}
	else if(document.forms[form_name][i].type == 'radio') {
		if  (document.forms[form_name][i].checked) {
			generated_string += "&" + document.forms[form_name][i].name + "=" + document.forms[form_name][i].value;
		}
	}
	else{
		generated_string += "&" + document.forms[form_name][i].name + "=" + document.forms[form_name][i].value;
	}
    }
	return generated_string;
}
/*
function load_form(post_vars, request_type){  
   
	xmlhttp= (window.XMLHttpRequest ? new XMLHttpRequest(): ((window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : null) );
	
	xmlhttp.open("POST",'ajax-handler/hs_ajax_handler.php',false);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	var send_val = "request_type=" + request_type +  post_vars;	
	
	xmlhttp.send(send_val);	
	return (xmlhttp.responseText);
	
}
*/
/*
function ajax_verification(tmp_target_msg_id, from_css, to_css, err_msg_style) {
	
	var invalid_fields;
	var target_form = this.form_name;
	var target_id = tmp_target_msg_id;
	
	var error_msg = '';
	
	return_value = load_form(this.post_vars, 'verification');
	
	
	if (return_value == "||"){
		var tmp_required_fileds = document.forms[target_form]['page_form_mandatory'].value;
			
		var required_fileds = tmp_required_fileds.split(",");
		
		for (i=0; required_fileds[i]; i++){
			field_id = required_fileds[i];
			style_id = 'hs_style_' + field_id;
			
			if(document.getElementById(style_id)){
				document.getElementById(style_id).className = from_css;
			}
			
			if(document.forms[target_form][field_id]){
				document.forms[target_form][field_id].value = '';
			}
		}	
		return true;
	}
		
	else{
		
		invalid_fields = return_value.split("||");
		
		if (invalid_fields[0]){
						
			var tmp_required_fileds = document.forms[target_form]['page_form_mandatory'].value;
			//alert(tmp_required_fileds);
			var required_fileds = tmp_required_fileds.split(",");
			
			
			for (i=0; required_fileds[i]; i++){
				style_id = 'hs_style_' + required_fileds[i];				
				if(document.getElementById(style_id)){
					document.getElementById(style_id).className = from_css;
				}
			}
			
			required_fileds = "";
			required_fileds = invalid_fields[0].split("::");
			
			for (i=0; required_fileds[i]; i++){
				style_id = 'hs_style_' + required_fileds[i];
				//
				error_msg += "Enter "+ required_fileds[i] +"<br/>";
				if(document.getElementById(style_id))
				{
					document.getElementById(style_id).className = to_css;
				}
			}
			//alert(error_msg);
		}
		
		if (invalid_fields[1]){

			var tmp_required_fileds = document.forms[target_form]['page_form_valid_email'].value;
			
			var required_fileds = tmp_required_fileds.split(",");
			for (i=0; required_fileds[i]; i++){
				style_id = 'hs_style_' + required_fileds[i];

				if(document.getElementById(style_id))
					document.getElementById(style_id).className = from_css;
			}
			
			required_fileds = "";
			required_fileds = invalid_fields[1].split("::");
			
			for (i=0; required_fileds[i]; i++){
				style_id = 'hs_style_' + required_fileds[i];
				//alert(required_fileds[i]);
				error_msg += "Enter Valid "+ required_fileds[i] +"<br/>";
				if(document.getElementById(style_id))
				{
					document.getElementById(style_id).className = to_css;
				}
			}
			//alert(error_msg);
		}
		if(error_msg!=''){
			document.getElementById(tmp_target_msg_id).innerHTML  = 'Please complete required fields.';//document.forms[target_form]['hs_page_form_err_message'].value;		
			document.getElementById(tmp_target_msg_id).className = err_msg_style;
		}
		
		//document.getElementById(tmp_target_msg_id).innerHTML  = error_msg;//document.forms[target_form]['hs_page_form_err_message'].value;		
		//document.getElementById(tmp_target_msg_id).className = err_msg_style;
		
		return false;
	}
}
*/
/*
function search_artist(form_name_param){	
	this.form_name = form_name_param;
	this.post_vars = get_form_value(this.form_name);
	
	
		if(others_varification()){
			return true;
			//return show_popup(post_vars);
		}
	
	
	return false;
}
*/
/*
function others_varification(){
	//alert(document.forms[form_name].action);
	//document.getElementById(form_name).action = document.forms[form_name]['hs_page_form_forward_page'].value;
	document.forms[form_name].action = document.forms[form_name]['page_form_forward_page'].value;	
	//document.forms[form_name].target
	return true;
}
*/

function save_draft(form_name_param){
	this.form_name = form_name_param;	
	this.post_vars = get_form_value();
	target_msg_id_draft = 'draft_message_tag';
	
/*	if(ajax_verification(target_msg_id, 'contact_text', 'contact_text_err', 'message_err')){*/
		if(save_by_ajax()){
			return false;
		}
		
/*	}*/
	return false;
}

function finish_save(return_value){
	try{
	id_list = return_value.split(",");
	if(id_list[0] == 'ok'){
		var curr_time = new Date();
		document.getElementById(target_msg_id_draft).innerHTML  = "Worksheets Saved at " + curr_time.getHours() + ":" + curr_time.getMinutes();// document.forms[this.form_name]['page_form_success_message'].value;
		/*	window.location = "contact-us.html";*/
		//	document.getElementById(target_msg_id).className = 'message_ok';
		alert('Draft Saved');
		set_ids_of_saved();
	}
	}
	catch(e){
		alert('Did not set ids ' + e.ToString());
	}
}

function process_save(){
	if (xmlhttp_s.readyState == 4){
		if (xmlhttp_s.status == 200){
			try{
				//alert(xmlhttp.responseText);
				finish_save(xmlhttp_s.responseText);
			}
			catch(e){
			}
		}
	}
}
/*
function save_to_db(){
	return_value = save_by_ajax();
	id_list = return_value.split(",");
	if(id_list[0] == 'ok'){
		return true;
	}
	else{
		return false;	
	}
}
*/

function save_by_ajax(){	
	//xmlhttp.onreadystatechange=state_change
	if (this.xmlhttp_s){
		try{
		this.xmlhttp_s.open("POST",'./savedraft.php',true);
		this.xmlhttp_s.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.xmlhttp_s.onreadystatechange=process_save;
		var send_val = this.post_vars;
		//alert(send_val);	
		this.xmlhttp_s.send(send_val);
		}
		catch(e){
		return false
		}
		return true;
	}
	return false;
}

function set_ids_of_saved(){
	document.getElementById('saved_to_db').value = "Yes";
	total_cnt = this.id_list.length;//document.getElementById('submitted_form_count');
	for (i = 1; i < total_cnt; i++)
	{
	//	alert(i + ':' + this.id_list[i]);
		hiddenid = 'hidden_id_' + (i - 1);
		document.getElementById(hiddenid).value = this.id_list[i];
	}
}

/*
function show_popup(post_vars){
	if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 && window.event.preventDefault) 
		window.event.preventDefault();
	this.newWindow = window.open('./artist-search-result.php?locale=en&' + post_vars, 'Search Result', 'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1');
	this.newWindow.focus();
	this.newWindow.opener=window;
	
	return false;	
}


function showVideo(various_img_file) {

video = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="177" height="133" id="FLVPlayer">'+
'<param name="movie" value="./FLVPlayer_Progressive.swf" />' +
'<param name="salign" value="lt" />' +
'<param name="quality" value="high" />' +
'<param name="scale" value="noscale" />' +
'<param name="FlashVars" value="&MM_ComponentVersion=1&skinName=' +
'Clear_Skin_1&streamName=./userfiles/video/image-upload/'+various_img_file+'&autoPlay=true&autoRewind=false" />' +
'<embed src="./FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName=' +
'Clear_Skin_1&streamName=./userfiles/video/image-upload/'+various_img_file+'&autoPlay=true&autoRewind=false"' +
'quality="high" scale="noscale" width="177" height="133" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash"'+
'pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

document.getElementById('pmaaustinvideo').innerHTML=video;
	
}*/

