/*

 * File: functions.js

 * Author: __name__ __email__

 * Copyright (c) alsoft.co.in 2010. All rights reserved.

 * Date: 07/07/2009

 * Version: 1.00

 * Email: support@alsoft.co.in

 * Web: http://www.alsoft.co.in

*/



var SITE_URL = 'http://www.mikili.net/';



function relocate(url) {

  window.location = url;

}



function preloading() {

	for ( i = 0; i < preloading.arguments.length; i++ ) {

		my_images[i] = new Image();

		my_images[i].src = preloading.arguments[i];

	}

}



function checkEmail(email) {

  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

  if ( !filter.test(email) ) {

    return false;

  } else {

    return true;

  }

}



function createCookie(name, value, days) {

	if (days) {

		var date = new Date();

		date.setTime(date.getTime()+(days*24*60*60*1000));

		var expires = "; expires=" + date.toGMTString();

	} else {

    var expires = "";

  }



  document.cookie = name + "=" + value + expires + "; path=/";

}



function readCookie(name) {

	var nameEQ = name + "=";

	var ca = document.cookie.split(';');

  

	for(var i = 0; i < ca.length; i++) {

		var c = ca[i];

		while (c.charAt(0) == ' ') {

      c = c.substring(1,c.length);

    }



		if (c.indexOf(nameEQ) == 0) {

      return c.substring(nameEQ.length,c.length);

    }

	}

	return null;

}



function eraseCookie(name) {

	createCookie(name, "", -1);

}



function trim(str, chars) {

	return ltrim(rtrim(str, chars), chars);

}



function ltrim(str, chars) {

	chars = chars || "\\s";

	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");

}



function rtrim(str, chars) {

	chars = chars || "\\s";

	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");

}



function delete_user(id) {

  var r = confirm('Are you sure you want to delete this user?');



  if ( r == true ) {

    window.location = 'admin_users.php?action=delete&id=' + id;

  }

}



function change_option(value, action, to_content) {

  if ( action == 1 ) {

    $('#'+ value + 'on').attr('src', 'images/checked.jpg');

    $('#'+ value + 'off').attr('src', 'images/not_checked.jpg');



    $('#' + to_content).val(action);

  } else {

    $('#'+ value + 'off').attr('src', 'images/checked.jpg');

    $('#'+ value + 'on').attr('src', 'images/not_checked.jpg');

    

    $('#' + to_content).val(action);

  }

}



function populate_provinces(country) {

  var country_id = parseInt($('#country').val());



  $('#province').removeOption(/./);

  $('#city').removeOption(/./);



  for ( var i in provinces ) {

    if ( provinces[i][0] == country_id ) {

      $('#province').addOption(provinces[i][1], provinces[i][2]);

    }

  }

  if ( country == '' ) {

    $('#province').selectOptions('');

  } else {

    $('#province').selectOptions(country);

  }

}



function populate_cities(city) {

  var province_id = parseInt($('#province').val());



  $('#city').removeOption(/./);



  for ( var i in cities ) {

    if ( cities[i][0] == province_id ) {

      $('#city').addOption(cities[i][1], cities[i][2]);

    }

  }

  if ( city == '' ) {

    $('#city').selectOptions('');

  } else {

    $('#city').selectOptions(city);

  }

}



function change_price(new_value, value) {

  var price = 0;



  if ( $('#logo').val() != '' ) {
     if(	ifn('logo_val'))
    price += parseInt($('#logo_val').html());
	

  }
  //alert(price+' after logo');

  if ( $('#cell').val() != '' ) {
if(	ifn('cell_val'))
    price += parseInt($('#cell_val').html());

  }
//alert(price);
  if ( $('#description_nopurify') && $('#description_nopurify').val() != '' ) {
 
										//alert(ifn('description_val'))
									if(	ifn('description_val'))
    price += parseInt($('#description_val').html());

  }
//alert(totimgs +'totimgs');
//alert(price);
  for ( var i = 1; i < totimgs; i++ ) {

    if ( $('#portfolio_images' + i).val() != '' ) {

      price += parseInt($('#images_val').html());
	 // alert("inif");
	 // alert($('#images_val').html());

    }

  }

  if ( $('#website').val() != '' ) {
if(	ifn('website_val'))
    price += parseInt($('#website_val').html());

  }

  if ( $('#video').val() != '' ) {
if(	ifn('video_val'))

    price += parseInt($('#video_val').html());

  }

  if ( $('#facebook').val() != '' ) {
if(	ifn('facebook_val'))
    price += parseInt($('#facebook_val').html());

  }

  if ( $('#skype').val() != '' ) {
   if(ifn('skype_val'))
    price += parseInt($('#skype_val').html());

  }

  if ( $('#twitter').val() != '' ) {
if(	ifn('twitter_val'))
    price += parseInt($('#twitter_val').html());

  }

  if ( $('#youtube').val() != '' ) {
if(	ifn('youtube_val'))
    price += parseInt($('#youtube_val').html());

  }

  if ( $('#myspace').val() != '' ) {
if(	ifn('myspace_val'))
    price += parseInt($('#myspace_val').html());

  }
//alert('finally price'+price);


  if ( price > 0 ) {

    price = price - ( price * discount_code ) / 100

  }



  update_price(price);

}



function update_price(new_value) {

  $('#my_price').html(new_value);

}

function ifn(iid)
{
	 if($('#'+iid).html()!=undefined)
	 return true;
	 else
	 return false;
	alert(isNaN($('#'+iid).html()))
 return (isNaN("'"+$('#'+iid).html()+"'"))	
	
}

var discount_code = 0;

function check_discount() {

  var discounted_code = $('#promotional_code').val();



  $.ajax({

    type: "POST",

    dataType: "html",

    url: "ajax_apply_code.php",

    data: "discount_code=" + discounted_code,

    success: function (msg) {

      discount_code = parseFloat(msg);

      if ( discount_code > 0 ) {

        $('#my_code').html(' ( -' + discount_code + '% )');

      } else {

        $('#my_code').html('');

      }

      change_price(0, 0);

    }

  });

}



function search_user(category) {

  window.location = 'browse/1/' + $('#category_id').val() + '&key=' + $('#key').val() + '&country=' + $('#country').val() + '&state=' + $('#province').val() + '&city=' + $('#city').val();

}



function search_jobs(category) {



	//alert($('#country').val().text);

	var city='';

	var state='';

	if($('#city').val() != '')

	{

		city = $("#city option[value='"+$('#city').val()+"']").text();

	}

	if($('#province').val() != '')

	{

		state = $("#province option[value='"+$('#province').val()+"']").text();

	}

   // var encoded = $.base64Encode('&key=' + $('#key').val() + '&country=' + $("#country option[value='"+$('#country').val()+"']").text() + '&state=' + state + '&city=' + city+ '&cid=' + $('#country').val()+ '&sid=' + $('#province').val()+ '&cityid=' + $('#city').val()+ '&sort=' + $('#srt').val());



  window.location = 'job_search/1/' + $('#category_id').val() + '&key=' + $('#key').val() + '&country=' + $("#country option[value='"+$('#country').val()+"']").text() + '&state=' + state + '&city=' + city+ '&cid=' + $('#country').val()+ '&sid=' + $('#province').val()+ '&cityid=' + $('#city').val()+ '&sort=' + $('#srt').val();

  //  window.location = 'job_search/1/'+$('#category_id').val() +encoded;

}



var zone = -1;

function ad_zone() {

  var max_zone = parseInt($('#sum_zone').html());

  var i = 0;



  zone++;

  zone = zone >= max_zone ? 0 : zone;



  for ( i = 0; i < max_zone; i++ ) {

    $('#ad_zone_' + i).css('display', 'none');

  }



  $('#ad_zone_' + zone).css('display', 'block');

}



function translate()

{

	var value = document.frm.FACEBOOK_LIKE.value;

	

	value     = value.replace('<','&lt;');

	value     = value.replace('>','&gt;');

	

	document.frm.FACEBOOK_LIKE.value = value;

	return true;

}



function calculate(price,value,symbol)

{

	var total =0;

	total = price * (value/10);

	

	document.getElementById('total').innerHTML = total + ' ' + symbol;

	

}



function openNewsPopup(lnk){

	//alert(lnk);

	window.open(lnk, '', 'width=900,height=600,resizable=yes,toolbar=no,menubar=no,status=no,location=no,titlebar=no,scrollbars=yes');

                   // $("#politicsIframe").attr('src', lnk);

					//alert($("#politicsIframe").attr('src'));

					//$('#politicsPopup').modal();

return false;

}
